预定义宏 | 描述 |
__DATE__ | (字符串常量)预处理的日期,格式为 Mmm dd yyyy |
__TIME__ | (字符串常量)预处理的时间,格式为 hh:mm:ss |
__FILE__ | (字符串常量)当前源文件的文件名 |
__LINE__ | (整数常量)在当前源文件中的行号 |
__STDC__ | (整数常量)设置为 1 |
__STDC_HOSTED__ | (整数常量)设置为 1 |
__STDC_VERSION__ | (整数常量)遵循 C99 标准时设置为 199901L 注释 1 |
/*
predefined macro
*/
#include <stdio.h>
void main(void)
{
printf("(__DATE__) : %s\n", __DATE__);
printf("(__TIME__) : %s\n", __TIME__);
printf("(__FILE__) : %s\n", __FILE__);
printf("(__LINE__) : %d\n", __LINE__);
printf("(__STDC__) : %d\n", __STDC__);
printf("(__STDC_HOSTED__) : %d\n", __STDC_HOSTED__);
#if __STDC_VERSION__ == 199901
printf("(__STDC_VERSION__) : %ld\n", __STDC_VERSION__);
#endif
}
malihou@ubuntu:~$
malihou@ubuntu:~$ gcc -std=c90 test.c
malihou@ubuntu:~$
malihou@ubuntu:~$ ./a.out
(__DATE__) : Nov 25 2012
(__TIME__) : 18:35:23
(__FILE__) : test.c
(__LINE__) : 12
(__STDC__) : 1
(__STDC_HOSTED__) : 1
malihou@ubuntu:~$
malihou@ubuntu:~$ gcc -std=c99 test.c
malihou@ubuntu:~$
malihou@ubuntu:~$ ./a.out
(__DATE__) : Nov 25 2012
(__TIME__) : 18:35:32
(__FILE__) : test.c
(__LINE__) : 12
(__STDC__) : 1
(__STDC_HOSTED__) : 1
(__STDC_VERSION__) : 199901
malihou@ubuntu:~$
/*
predefined macro & identifier
*/
void main(void)
{
printf("file is %s\n", __FILE__);
printf("function is %s\n", __func__);
}
malihou@ubuntu:~$
malihou@ubuntu:~$ gcc -E test.c
# 1 "test.c"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "test.c"
void main(void)
{
printf("file is %s\n", "test.c");
printf("function is %s\n", __func__);
}
malihou@ubuntu:~$
联系客服