//__func__(C99)不是宏,而是每个函数都有的字符串:
//当前函数的名称
const char *whereAmI(void) {
return __func__;
}
const char *function = whereAmI();
//function is "whereAmI"
//__FILE__ 和 __LINE__:正在编译的文件和行号。
//消息可以指出自己来自哪里
#define LOG(message) printf("%s:%d: %s\n", __FILE__, __LINE__, message)
//#line 同时设置两者,代码生成器就是这样做的
#line 100 "demo.c"
int line = __LINE__;
const char *file = __FILE__;
LOG("started");
//line is 100, file is "demo.c"
//printed "demo.c:102: started"
//__DATE__ 和 __TIME__:程序编译的时间
const char *buildDate = __DATE__;
//buildDate 是构建日期,形如 "Sep 30 2026"
const char *buildTime = __TIME__;
//buildTime 是构建时间,形如 "14:05:09"
//标准版本:199901 是 C99、201112 是 C11、
//201710 是 C17、202311 是 C23
long version = __STDC_VERSION__;
//version is 202311
printf("function is %s\n", function);
printf("line is %d\n", line);
printf("file is %s\n", file);
printf("buildDate is %s\n", buildDate);
printf("buildTime is %s\n", buildTime);
printf("version is %ld\n", version);