C语言中的预定义宏

C语言中的预定义宏

c语言中有些预定义的宏,十分常用

1
2
3
4
5
6
__FILE__: 文件名
__FUNCTION__: 函数名
__LINE__: 代码行号
__TIME__: 编译时间
__DATE__: 编译日期
__TIMESTAMP__: 时间戳

define中的三个特殊符号

1
2
3
# 添加双引号
## 两个变量字符串化后连接
#@ 添加单引号

clang编译器编译阶段参数

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
> man clang
-E Run the preprocessor stage.

-fsyntax-only
Run the preprocessor, parser and type checking stages.

-S Run the previous stages as well as LLVM generation and optimization stages and
target-specific code generation, producing an assembly file.

-c Run all of the above, plus the assembler, generating a target ".o" object file.

no stage selection option
If no stage selection option is specified, all stages above are run, and the linker is run to
combine the results into an executable or shared library.

例子:

1
2
3
4
5
6
7
# 预处理
cc -E /tmp/example.c -o /tmp/example.i
# 汇编器
cc -S /tmp/example.i -o /tmp/example.s
# 编译器
cc -c /tmp/example.s -o /tmp/example.o
# 后面还有链接相关的处理

参考