c 基础

编译器内置标准预定义宏:

__LINE__:在源代码中插入当前源代码行号;

__FILE__:在源文件中插入当前源文件名;

__DATE__:在源文件中插入当前的编译日期;

__TIME__:在源文件中插入当前编译时间;

__FUNCTION__:在源文件中插入当前方法名;

__STDC__:当要求程序严格遵循 ANSI C 标准时该标识被赋值为 1;

__VA_ARGS:代表可变参数...

__cplusplus:当编写 C++ 程序时该标识符被定义。

同时#line 可用来重新设定__LINE__的值,举例如下:

1
2
3
4
5
6
7
8
#include <stdio.h>

int main(int argc, char** argv){
    printf("current line number: %d\n", __LINE__);
#line 150 //指定下一行的__LINE__为 150
    printf("current line number: %d\n", __LINE__);
    exit 0;
}

输出为:

4
150