Hi,How to understand Visual C++ stack alignment?
-
Dear Experts, I test such code in Visual C++ 6.0 as following: #include #include int main() { char c0; char c1; char c2; printf("%p\n%p\n%p\n",&c0,&c1,&c2); return 0; } In "DEBUG" build mode without optimizationm, the output is : 0012FF7C 0012FF78 0012FF74 In "RELEASE" build mode without optimization, the output is : 0012FF7C 0012FF78 0012FF74 In "RELEASE" build mode with "Maxmize Speed" optimization, the output is: 0012FF7D 0012FF7E 0012FF7F So, as above, in stack, there are redundant bytes in these "char" variables. Why? Why Visual C++ compiler insert redundant bytes into stack? :confused: Your Sincerely REMY
-
Dear Experts, I test such code in Visual C++ 6.0 as following: #include #include int main() { char c0; char c1; char c2; printf("%p\n%p\n%p\n",&c0,&c1,&c2); return 0; } In "DEBUG" build mode without optimizationm, the output is : 0012FF7C 0012FF78 0012FF74 In "RELEASE" build mode without optimization, the output is : 0012FF7C 0012FF78 0012FF74 In "RELEASE" build mode with "Maxmize Speed" optimization, the output is: 0012FF7D 0012FF7E 0012FF7F So, as above, in stack, there are redundant bytes in these "char" variables. Why? Why Visual C++ compiler insert redundant bytes into stack? :confused: Your Sincerely REMY
I'm not sure but I'd guess it has something to do with char-to-int promotion.
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb