c++ - Is sizeof() recursive? -
the answer should simple, wanted make sure.
is sizeof() recursive? instance,
struct foo { dword a; dword b; }; struct bar { dword c; foo d; }; would sizeof(bar) include size of foo, returning full 12 bytes (assuming dword 4 bytes)?
yes... sizeof gives total of members directly included in type, including struct/class data members, non-virtual base classes, implementation-defined links/counters tracking virtual bases, virtual dispatch table pointers, padding helps align data members cpu-safe or -efficient access, , theoretically else implementation may feel putting in there! (for example, run-time debugging / error detection, non-standard support of garbage collection...)
of course, doesn't include size of pointed-to or referenced objects, include size of pointers , references.
Comments
Post a Comment