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)?
Asked
Active
Viewed 69 times
1
-
I think it is also depends on word size and alignment. – Zang MingJie Nov 06 '15 at 09:26
-
@ZangMingJie I meant only a process-wide guarantee. Will edit. – Museful Nov 06 '15 at 09:28
1 Answers
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
-
-
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