介绍几种常见的C语言预处理标识符
__LINE__; __FILE__; __DATE__; __TIME__; #; ##;
__LINE__ :当前源代码的行号,为整型常量
__FILE__ :当前编译程序文件的名称,为字符串
__DATE__:编译程序文件日期,
为字符串(”MM DD YYYY"形式,如”Qct 18 2016”)
__TIME__:编译程序文件时间,
__FILE__ :当前编译程序文件的名称,为字符串
__DATE__:编译程序文件日期,
为字符串(”MM DD YYYY"形式,如”Qct 18 2016”)
__TIME__:编译程序文件时间,
为字符串("hh:mm:ss"形式,如”16:39:30”)
在ANSI C中为预编译指令定义了两个运算符——#和##。# 的作用是实现文本替换,例如:
#include <stdio.h>
#include <windows.h>
#define DATA 10
#define PRINT(FORMAT, VALUE) \
printf("this value of "#VALUE" is "FORMAT"\n",VALUE)
int main()
{
PRINT("%d", DATA);
system("pause");
return 0;
}
#include <windows.h>
#define DATA 10
#define PRINT(FORMAT, VALUE) \
printf("this value of "#VALUE" is "FORMAT"\n",VALUE)
int main()
{
PRINT("%d", DATA);
system("pause");
return 0;
}
程序运行结果是:the value of DATA is 10.
##的作用是串连接。例如:
#include<stdio.h>
#include<windows.h>
#define str1 "hello"
#define str2 "world"
#define str1str2 "hello bit."
#define CONNECT(x,y)\
x##y
int main()
{
printf("%s%s",CONNECT(str1,str2));
system("pause");
return 0;
#include<windows.h>
#define str1 "hello"
#define str2 "world"
#define str1str2 "hello bit."
#define CONNECT(x,y)\
x##y
int main()
{
printf("%s%s",CONNECT(str1,str2));
system("pause");
return 0;
}
程序运行结果是:hello bit.