c++ - Why is the memory of a global structure and a member variable (of the same type) set equal to the global different? -
i constructing object so:
testobj::testobj(const typedefstruct& mystruct) : m_memberstruct(mystruct){}
the struct looks this:
typedef struct{ short x; short y;} typedefstruct;
. public member of class testobj
.`
when compare memory of global mystruct
being passed constructor , m_memberstruct
member variable of testobj
, memory contents differ.
ps: initializing global struct so: testobj::typedefstruct mystruct = {0};
i have read compilers pad elements of struct make each element same size, , that can interfere comparing memory of global struct , "copy" of it, don't think applies here because same-type two-element struct...
any insight on situation? if cannot compare memory besides checking values of 2 elements still understand why memory contents different.
the compiler can pad m_memberstruct because part of testobj. is, may try give testobj proper alignment.
Comments
Post a Comment