How to calculate the offset of fields in a (list) struct/object

  • Suppose we have a struct definition as follows:

      struct myStruct
      {
          ...    ^
          ...    | offset
          ...    |
          ...    v
          int   x;
          ...
          ...
      }
    

    Then:

    • The offset of the field x (from the base address of the struct variable) is:

         number of bytes  used  for the variables  prior to x