分类: C/C++
2008-04-05 23:02:10
.c文件经过预处理(gcc 时带上 -E选项)产生.i文件……
预处理 编译 汇编 连接
.c------------>.i------------>.s------------>.o------------>a.out
-E -S -c
过程图
[实例] 注意define和const的区别
#define MAX 2048
int main(void)
{
const int max = 1024;
char s1[MAX] = "abc";
int i = max * 2;
printf("%s\n", s1);
printf("%d\n", i);
}
~
"gcc.c"
eleven@linux:~> gcc -E gcc.c
# 1 "gcc.c"
# 1 "
# 1 "
# 1 "gcc.c"
int main(void)
{
const int max = 1024;
char s1[2048] = "abc";
int i = max * 2;
printf("%s\n", s1);
printf("%d\n", i);
}
eleven@linux:~> gcc -S gcc.c
eleven@linux:~> ls
gcc.c gcc.s
eleven@linux:~> cat gcc.s
.file "gcc.c"
.section .rodata
.LC0:
.string "abc"
.zero 2044
.LC1:
.string "%s\n"
.LC2:
.string "%d\n"
.text
.globl main
.type main, @function
main:
pushl %ebp
movl %esp, %ebp
pushl %edi
subl $2084, %esp
andl $-16, %esp
movl $0, %eax
addl $15, %eax
addl $15, %eax
shrl $4, %eax
sall $4, %eax
subl %eax, %esp
movl $1024, -12(%ebp)
movl .LC0, %eax
movl %eax, -2072(%ebp)
leal -2068(%ebp), %edi
cld
movl $0, %edx
movl $511, %eax
movl %eax, %ecx
movl %edx, %eax
rep
stosl
movl -12(%ebp), %eax
addl %eax, %eax
movl %eax, -2076(%ebp)
subl $8, %esp
leal -2072(%ebp), %eax
pushl %eax
pushl $.LC1
call printf
addl $16, %esp
subl $8, %esp
pushl -2076(%ebp)
pushl $.LC2
call printf
addl $16, %esp
movl -4(%ebp), %edi
leave
ret
.size main, .-main
.section .note.GNU-stack,"",@progbits
.ident "GCC: (GNU)
eleven@linux:~> ls
gcc.c gcc.s
eleven@linux:~> gcc gcc.c
eleven@linux:~> ls
a.out gcc.c gcc.s
===================================