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

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -