GCC预处理程序规则
2017-02-22 17:14
302 查看
/* 限定只有在定义了__unix__的情况下才能成功编译 */ #ifndef __unix__ #error "This section will only work on UNIX systems" #endif /* 插入指定的文件 */ #include <errno.h> #include <stdio.h> #include <stdlib.h> /* 两值中的最小值 */ #define min(a,b) ((a) < (b) ? (a) : (b)) /* 替换是递归式的 */ #define TANKARD TSIZE #define TSIZE 100 /* 删除宏定义 */ #define MLKEYVAL 889 #undef MLKEYVAL /* 含参数的宏定义,宏名和括号间不能有空格 */ #define decint(a) (a-1) #define incint (a) (a+1) // 错误 /* 宏参数前加上“#”可将其“字符串化” */ #define MONCK(ARGTERM) \ printf("The term " #ARGTERM " is a string\n"); /* 宏内部连接 */ #define frontback "frontback" #define PASTE(a,b) a##b /* 可变参数宏 */ #define prnt(...) printf(__VA_ARGS__); #define errout(a,b,...) \ fprintf(stderr, "File:%s Line:%d ", a, b); \ fprintf(stderr, __VA_ARGS__); \ fflush(stderr); #define errexit(fmt, ...) do { \ fprintf(stderr, fmt"\n", ##__VA_ARGS__); \ exit(EXIT_FAILURE); \ } while (0) int main(void) { prnt("min=%d\n", min(2,3)); prnt("TANKARD=%d\n", TANKARD); #ifndef MLKEYVAL prnt("MLKEYVAL is undef\n"); #else # define NOKEYVAL /* 可以定义没有值的宏 */ #endif #if !defined(NOKEYVAL) prnt("NOKEYVAL is def\n"); #endif printf("decint(10)=%d\n", decint(10)); MONCK("a+b=c"); MONCK(123); printf("PASTE(front,back)=%s\n", PASTE(front,back)); errout(__FILE__, __LINE__, "Func:%s\n", __func__); errexit("exit"); return 0; }
测试:
:~$ ./pretreatment min=2 TANKARD=100 MLKEYVAL is undef NOKEYVAL is def decint(10)=9 The term "a+b=c" is a string The term 123 is a string PASTE(front,back)=frontback File:pretreatment.c Line:64 Func:main exit
相关文章推荐
- 1.2.在linux环境实践,使用vim编写一个程序,然后使用gcc查看【预处理】、【编译】、【汇编】、【链接】各阶段文件的内容。并熟悉相关指令。
- Linux操作系统的简单指令及如何使用vim编写一个程序,然后使用gcc查看【预处理】、【编译】、【汇编】、【链接】各阶段文件的内容。
- 【Linux】使用vim编写一个程序,gcc查看预处理、编译、汇编、链接过程
- GCC 预处理 编译 汇编 链接全过程及其含义 程序的开始不是main函数
- uc笔记01---Unix,Linux,程序构建过程,gcc,头文件,预处理,环境变量配置
- gcc编译程序的四个阶段(预处理-编译-汇编-链接)
- C++ gcc 程序时出问题
- MAC中使用Vim和GCC编译C程序
- iOS开发笔记系列-基础6(预处理程序)
- premake 在64位Ubuntu系统下编译32位GCC程序
- gcc预处理阶段
- Java程序练习:设计用户输入界面,获取网址采集规则
- 利用GCC预处理展开宏
- gcc编译C++程序
- 写了一个能自定义并自动按照规则生成单据号码的程序及相关存储过程和表,及示范,附全部源代码!
- linux gcc编译C程序
- gcc编译简单的程序
- gcc -g参数对程序大小的影响
- linux下c程序编译过程及GCC,G++, GDB简介
- GCC编译的背后( 预处理和编译 汇编和链接 )