On Fri, 2009-04-10 at 03:16 -0700, John (Eljay) Love-Jensen wrote: > Hi Bob, > > > Now the stack is no longer 16-byte aligned. > > Leaf functions do not need to maintain stack alignment. > main is not a leaf function here. It calls foo. > > Furthermore, this stack alignment could have been accomplished by allocating only the 8 bytes needed for the local variable, sum. > > Optimized code, or non-optimized? > > If it is non-optimized (-O0, which is the default if not specified), non-optimized code may be non-optimal. > It was non-optimized. But I still expected the compiler not to allocate 16 bytes on the local stack frame for no reason. Oddly (to me) int main( void ) { long sum = foo( 3, 4, 5, 6, 7 ); return 0; } produces: main: pushq %rbp movq %rsp, %rbp subq $16, %rsp int main( void ) { long sum = foo( 3, 4, 5, 6, 7 ); } produces: main: pushq %rbp movq %rsp, %rbp subq $24, %rsp and void main( void ) { long sum = foo( 3, 4, 5, 6, 7 ); } produces: main: pushq %rbp movq %rsp, %rbp subq $16, %rsp My "application" here is an x86-64 textbook I have written. The point of my book is to show how the machine works at the instruction set level when code is written at the C/C++ level. So I start my examples with C/C ++ code. The book serves as an introduction to architecture. It's not an assembly language book, nor a compiler book. But I would like to be able to explain things in the book that the student might see when he/she replicates my examples. I do have a "your mileage may vary" due to different gcc/as versions. Bob