1

If a class is_standard_layout, is that sufficient to guarantee that a given non-static data member will always have the same offset from the object's address (i.e. same across different instances of that class, process-wide)?

Museful
  • 6,711
  • 5
  • 42
  • 68

1 Answers1

2

That effectively has to hold for objects of any type (within a program). Accessing a subobject happens via offsets which are known at compile-time and constant in machine code. For SL types, you can verify this via offsetof - which is guaranteed to work for standard-layout types and basically implies a uniform offset.

Columbo
  • 60,038
  • 8
  • 155
  • 203
  • It says [here](http://www.cplusplus.com/reference/cstddef/offsetof/) that `offsetof` requires a POD class, which is a stronger requirement than standard_layout. That is why I came here to ask. – Museful Nov 06 '15 at 09:34
  • @tennenrishin Check the C++11 tab. – Columbo Nov 06 '15 at 09:34
  • Oh a browser plugin was preventing it from rendering the tabs so it was listing all the requirements from all the standards! That really unconfused my day for me. Thanks. – Museful Nov 06 '15 at 09:40