4.32 Anonymous Unions
Within a record
declaration you can place a union
declaration without specifying a fieldname for the union
object. The following example demonstrates the syntax for this:
type HasAnonUnion: record r:real64; union u:uns32; i:int32; endunion; s:string; endrecord; static v: HasAnonUnion;
Whenever an anonymous union appears within a record
you can access the fields of the union
as though they were direct fields of the record
. In the example above, for example, you would access v
's u
and i
fields using the syntax v.u
and v.i
, respectively. The u
and i
fields have the same offset in the record (8, because they follow a real64
object). The fields of v
have the following offsets from v
's base address:
v.r 0 v.u 8 v.i 8 v.s 12
@size(v) ...
Get The Art of Assembly Language, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.