I just compared the unoptimized gcc assembler output:
# cat while.c int main() { while(1) {}; return 0; }
Draw the assembler output:
# gcc -S while.c # gcc -S forloop.c
Compare assembler files:
# diff forloop.s while.s 1c1 < .file "forloop.c" --- > .file "while.c"
As you can see, there are no significant differences. Here is the conclusion
# cat while.s .file "while.c" .text .globl main .type main, @function main: pushl %ebp movl %esp, %ebp .L2: jmp .L2 # this is the loop in both cases .size main, .-main .ident "GCC: (GNU) 4.4.3" .section .note.GNU-stack,"",@progbits
Although this is not technical evidence that they are the same, I would say that it is in 99.9% of cases.
Otto Allmendinger Feb 18 2018-10-18 13:34
source share