If you look at the assembly generated by this code:
int main () { int i = 1; while (i) ; return 0; }
Unsigned -O2:
.file "test.c" .text .globl main .type main, @function main: pushl %ebp movl %esp, %ebp subl $16, %esp movl $1, -4(%ebp) .L2: cmpl $0, -4(%ebp) jne .L2 movl $0, %eax leave ret .size main, .-main .ident "GCC: (Ubuntu 4.4.3-4ubuntu5) 4.4.3" .section .note.GNU-stack,"",@progbits
With the -O2 flag:
.file "test.c" .text .p2align 4,,15 .globl main .type main, @function main: pushl %ebp movl %esp, %ebp .L2: jmp .L2 .size main, .-main .ident "GCC: (Ubuntu 4.4.3-4ubuntu5) 4.4.3" .section .note.GNU-stack,"",@progbits
With the -O2 flag, declaration i and the return value are omitted, and you only have a label that jumps to the same label to form an infinite loop.
Without the -O2 flag, you can clearly see the distribution of space i on the stack ( subl $16, %esp ) and initialization ( movl $1, -4(%ebp) ), as well as an estimate of the while condition ( cmpl $0, -4(%ebp) ) and the return value of the main function ( movl $0, %eax ).
Opera source share