I have a 32-bit C++ program here, and was checking disassembly out of curiosity. I have the following struct:
struct Blah
{
char foo;
std::strin开发者_开发技巧g bar;
};
When accessing blah->bar, I noted the following:
; ... address of blah is in eax
003A227B add eax,4
So my question is, why does 4 needed to be added to blah
's address to get to bar
? I would understand 3, because char
is 1 byte and that would make a nice round 4...
It is adding 4 to the base address of blah
. I guess that is the same as adding 3 to the address just after foo
. :)
It is indeed an alignment issue. Pointers should be aligned on address which are a multiple of 4.
精彩评论