Device Monitoring Studio - Monitor, log and analyze data coming through PC ports and connections
Docs

Structures

A structure is a combination of data fields. A structure occupies space required to store all its fields, one by one, subject to structure packing or alignment.

A structure definition consists of zero or more of data fields:

type var-decl [, var-decl…];

where var-decl is:

(id | id[array-size-expression] | id:bit-field-size-expression | id as type-id *)

A structure may contain different fields with a same name. If such a field is referenced in expression, an [] operator may be used to address individual fields. If this operator is not used, the first field is referenced.

Typedefs, constants, enumerations, native functions and nested user-defined types are also allowed within a structure definition.

Plain field, array field, bit field and pointer field are described in more detail in their corresponding sections.

Empty structures are eliminated from the output. See also the noautohide attribute section.

Example:

struct A
{
    int a;               // plain data field
    int b:3;             // bit-field
    int c[10];           // array
    int d as B *;        // pointer
    
    short s,t[5],u:12;   // multiple fields may be combined
};

Packing and Alignment

The important thing about user-defined types is the size and alignment of a type. The size of the structure is a sum of sizes of all its fields (subject to alignment). The alignment of the built-in type equals its size, and alignment of the structure is calculated by Device Monitoring Studio, taking in account the alignment of all structure fields and current structure packing value. By default, structure packing value is 1.

You may change the structure packing value using the following directive:

#pragma pack(N)

where N is one of the following values: 1, 2, 4, 8, 16, 32.

NOTE

The following rule is used when computing the alignment of each structure field:

Each data field starts at offset which is a multiple of its alignment. A number of unused padding bytes is inserted if required, but no more than the current structure packing value.

The implementation of structure packing and field alignment in Device Monitoring Studio complies with standard C implementation.

Byte Order

By default, Device Monitoring Studio respects the current byte order specified for the editor window. You can change the byte order at any time using the following directive:

#pragma byte_order(LittleEndian | BigEndian | Default)

This directive changes the current byte order until the end of the current scope, or until another byte_order directive.