The answer should be simple, but I wanted to make sure.
Is sizeof() recursive? For instance,
struct foo
{
DWORD a;
DWORD b;
};
struct bar
{
DWORD c;
foo d;
};
would a sizeof(bar) include the size of foo, returning a full 12 bytes (assuming DWORD is 4 bytes)?
Yes…
sizeofgives a total of all the members directly included in the type, includingstruct/classdata members, non-virtual base classes, some implementation-defined links/counters tracking virtual bases, virtual dispatch table pointers, padding that helps align data members for CPU-safe or -efficient access, and theoretically anything else the implementation may feel like putting in there! (for example, something for run-time debugging / error detection, non-Standard support of garbage collection…)Of course, it doesn’t include the size of pointed-to or referenced objects, but does include the size of those pointers and references.