C语言预定义宏用法
引导语;预定义的宏不采用任何参数,并且不能重新定义。以下是本站小编分享给大家的.C语言预定义宏用法,欢迎阅读!
预定义宏
__DATE__进行预处理的日期(“Mmm dd yyyy”形式的字符串文本)
__FILE__代表当前源代码文件名的字符串文本
__BASE_FILE__获取正在编译的源文件名
__LINE__代表当前源代码文件中的行号的整数常量
__TIME__源文件编译时间,格式为“hh: mm: ss”
__STDC__设置为 1时,表示该实现遵循 C标准
__STDC_HOSTED__为本机环境设置为 1,否则设为 0
__STDC_VERSION__为C99时设置为199901L
__FUNCTION__或者 __func__ 获取所在的函数名(预定义标识符,而非预定义宏)
#include
int main (void)
{
printf ("The file is %sn", __FILE__);
printf ("The base_file is %sn", __BASE_FILE__);
printf ("The line is %dn", __LINE__);
printf ("The function is %sn", __FUNCTION__);
printf ("The func is %sn", __func__);
printf ("The date is %sn", __DATE__);
printf ("The time is %sn", __TIME__);
return 0;
}
输出结果:
The file is part.c
The base_file is part.c
The line is 6
The function is main
The func is main
The date is Nov 22 2016
The time is 15:46:30