[root@localhost ansi]# cpp -dM /dev/null //查看GCC内部自定义的宏第一:通过使用宏去掉注释[root@localhost ansi]# vim dtest.c #include <stdio.h> int main(void){#ifdef TEST printf("Test mode
");#endif printf("Tuning......
"); return 0;}1、使用宏(拿掉#if 0 …………#end if的注释)[root@localhost ansi]# gcc -Wall -O -DTEST dtest.c -o dt[root@localhost ansi]# ./dtTest modeTuning......2、不使用宏[root@localhost ansi]# gcc -Wall -O dtest.c -o wanyan[root@localhost ansi]# ./wanyan Tuning......第二:通过宏实现赋值[root@localhost ansi]# vim num.c #include <stdio.h> int main(void){ printf("Value of NUM is %d
",NUM); return 0;}1、只写-D默认的值为1(正确)[root@localhost ansi]# gcc -Wall -O -DNUM num.c -o num[root@localhost ansi]# ./num Value of NUM is 12、给D赋值(正确)[root@localhost ansi]# gcc -Wall -O -DNUM=123 num.c -o wanyan[root@localhost ansi]# ./wanyan Value of NUM is 1233、不写-D(错误)[root@localhost ansi]# gcc -Wall -O num.c -o ethnicitybetanum.c: In function "main":num.c:5: error: "NUM" undeclared (first use in this function)num.c:5: error: (Each undeclared identifier is reported only oncenum.c:5: error: for each function it appears in.)第三:编译的过程(模拟),过程.c(原始代码部分)-->.i(预处理的部分)-->.s(汇编语言部分)-->.o(包含机器码的部分,目标文件)-->可执行的文件[root@localhost test]# vim bad.c #include <stdio.h> int main(void){ printf("2 plus 2 is %d
",4); return 0;}~ 下边这个步骤就是为了保存预处理的结果文件 [root@localhost test]# gcc -Wall -O -c -save-temps bad.c //重点在-save-temps的使用[root@localhost test]# lsbad.c bad.i bad.o bad.s第四:GCC –E来查看过程(并不是真正的编译)[root@localhost test]# vim bad.c #include <stdio.h> int main(void){ printf("2 plus 2 is %d
",4); return 0;} [root@localhost test]# gcc -E bad.c………..…………………..extern void funlockfile (FILE *__stream) __attribute__ ((__nothrow__));# 844 "/usr/include/stdio.h" 3 4 # 2 "bad.c" 2 int main(void){ printf("2 plus 2 is %d
",4); return 0;}实验结束Linux下GCC的DEBUG和优化,以及编译过程Lnux下GNU C和standard C(ANSI/ISO)区分实例相关资讯 gcc
- gcc: error trying to exec " (今 06:25)
- GCC 6.1带来新的C++17特性、完全支 (05月06日)
- Linux环境下使用GCC编译,GDB反汇 (03月30日)
| - 用GCC进行程序的编译 (06月14日)
- GNU编译器套件GCC 6.1发布 默认使 (04月28日)
- 让GCC支持成员函数模板的trick (03月10日)
|
本文评论 查看全部评论 (0)