sizeof and __offsetof

  • sizeof(Type) gives the size of a type in bytes.
  • __offsetof(Struct, field_name) gives the offset in bytes of a struct field.
  1. struct Foo {
  2. a int
  3. b int
  4. }
  5. assert sizeof(Foo) == 8
  6. assert __offsetof(Foo, a) == 0
  7. assert __offsetof(Foo, b) == 4