First program's c code
Code:
#include <stdio.h>
int main(void)
{
printf("Hello World!\n");
return 0;
}
compiled with -O3 to assembly
Code:
.file "tmp.c"
.version "01.01"
gcc2_compiled.:
.section .rodata
.LC0:
.string "Hello World!\n"
.text
.align 4
.globl main
.type main,@function
main:
pushl %ebp
movl %esp,%ebp
pushl $.LC0
call printf
xorl %eax,%eax
leave
ret
.Lfe1:
.size main,.Lfe1-main
.ident "GCC: (GNU) egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)"
Second program's c code
Code:
#include <stdio.h>
int main(void)
{
char* s = "Hello World!\n";
printf(s);
return 0;
}
Compiled with gcc -O3
Code:
.file "tmp1.c"
.version "01.01"
gcc2_compiled.:
.section .rodata
.LC0:
.string "Hello World!\n"
.text
.align 4
.globl main
.type main,@function
main:
pushl %ebp
movl %esp,%ebp
pushl $.LC0
call printf
xorl %eax,%eax
leave
ret
.Lfe1:
.size main,.Lfe1-main
.ident "GCC: (GNU) egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)"
And surprisingly it is the same assembly output.