Next: , Previous: , Up: Structs   [Contents][Index]

14.5.10 The OFFSET variable

The offset of the current field being mapped or constructed, relative to the beginning of the struct, is at all times available in a variable called OFFSET. This is useful in situations where we need that information in a constraint expression, the boundary of an array, an initialization value, or the like.

For example, what follows is a typical usage of OFFSET in order to introduce some padding in a struct:

type Elf64_Note =

    Elf64_Xword name;
    byte[alignto (OFFSET, 4#B)] padding;


The value of this variable changes every time a new field is mapped or constructed, so writing to it will only have effect until the next field is processed: at that time the value will be overwritten.