Element location arrangement in Structure Definition

Source: Internet
Author: User

In the record structure definition, the type that requires the same value comparison is defined in a continuous range. It will be convenient for subsequent processing.

For example, format block version Definition

 
// 1 data version structure ‑ dataedition = ^ tdfdataedition; tdfdataedition = packed record size: integer; // structure size Ver: word; // version number Len: integer; // Data Length <--- this value changes with the length of the stored data block. Name: array [0 .. 5] of char; end;

In this case, it is annoying to compare whether the version types are the same. You need to cross the Len definition.

Result: = (v1.size = v2.size) and (v1.ver = v2.ver) and (v1.name [0] = v2.name [0]) and (v1.name [1] = v2.name [1]) and (v1.name [2] = v2.name [2]) and (v1.name [3] = v2.name [3]) and (v1.name [4] = v2.name [4]);

When values of the same type are defined together

 
// 1. The new data version structure is paidataedition = ^ tdfdataedition; tdfdataedition = packed record size: integer; // structure size Ver: word; // version number name: array [0 .. 5] of char; Len: integer; // Data Length <--- move the variable-length object to the end, which may be very different from the end;

Comparison functions are much simpler.

 result: = comparemem (V1, V2, sizeof (tdfdataedition)-4 ); 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.