delphi - Absolute addressing fields in a record type -


this question has answer here:

i attempting interface embedded system transmits , receives data simple format has strict sizing requirements.

in c, use union type expose variable data potentially different types located @ same spot in memory. add variable of union type struct, , can (carefully) refer struct field various names , types:

for simplicity, please ignore byte alignment , packing

typedef enum { f1_v1, f1_v2, f1_v3 } flag_1_t; typedef enum { f2_v1, f2_v1        } flag_2_t;  typedef union {   flag_1_t flag_1;   flag_2_t flag_2; } flag_t;  typedef struct {   byte_t  id;   int32_t value;   flag_t  flag; } data_item_t; 

so can interpret flag field either flag_1_t or flag_2_t.

i use same sort of approach in delphi 2010. i've tried accomplish using absolute addressing fields of record:

type   flag_1_t = ( f1_v1, f1_v2, f1_v3 );   flag_2_t = ( f1_v1, f1_v2        );  type   data_item_t = record     id     : byte_t;     value  : int32_t;     flag_1 : flag_1_t;     flag_2 : flag_2_t absolute flag_1;   end; 

but fails compile syntax error e2029 ';' expected identifier 'absolute' found.

if bring flag declarations outside of record type definition (but @ same scope record type def), compiles fine:

note useless i'm trying accomplish

type   flag_1_t = ( f1_v1, f1_v2, f1_v3 );   flag_2_t = ( f1_v1, f1_v2        );  type   data_item_t = record     id     : byte_t;     value  : int32_t;   end;  var   flag_1 : flag_1_t;   flag_2 : flag_2_t absolute flag_1; 

so why can't within record? there way accomplish this?

you can translate c union delphi using record type variant part:

type   flag_t = record     case boolean of       false: (flag_1: flag_1_t);       true: (flag_2: flag_2_t);   end; 

Comments

Popular posts from this blog

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Magento/PHP - Get phones on all members in a customer group -

session - Logging Out Using PHP -