转载自:https://blog.csdn.net/weixin_43914889/article/details/105064843
C标准规定了一些预定义宏
C99 标准提供一个名为_ func 的预定义标识符,它展开为一个代表函数名的字符串(该函数包含该标识符)。那么, func 必须具有函数作用域,而从本质上看宏具有文件作用域。因此, func _是C语言的预定义标识符,而不是预定义宏。
注意,其中一些是C99 新增的,所以不支持C99的编译器可能无法识别它们。如果使用 GCC,必须设置-std=c99或-std=c11。
// predef.c -- 预定义宏和预定义标识符
#include <stdio.h>
void why_me();
int main()
{
printf("The file is %s.\n", __FILE__);
printf("The date is %s.\n", __DATE__);
printf("The time is %s.\n", __TIME__);
printf("The version is %ld.\n", __STDC_VERSION__);
printf("This is line %d.\n", __LINE__);
printf("This function is %s\n", __func__);
why_me();
return 0;
}
void why_me()
{
printf("This function is %s\n", __func__);
printf("This is line %d.\n", __LINE__);
}
//下面是该程序的输出:
The file is predef.c.
The date is Sep 23 2013.
The time is 22:01:09.
The version is 201112.
This is line 11.
This function is main
This function is why_me
This is line 21.