青岛城阳区清理下水道:C语言的6个标准宏

来源:百度文库 编辑:九乡新闻网 时间:2024/07/07 15:27:28


ANSIC标准定义了以下6种可供C语言使用的预定义宏:
__LINE__ 在源代码中插入当前源代码行号
__FILE__ 在源代码中插入当前源代码文件名
__DATE__ 在源代码中插入当前编译日期〔注意和当前系统日期区别开来〕
__TIME__ 在源代码中插入当前编译时间〔注意和当前系统时间区别开来〕
__STDC__ 当要求程序严格遵循ANSIC标准时该标识符被赋值为1。
__cplusplus
标识符__LINE__和__FILE__通常用来调试程序;
标识符__DATE__和__TIME__通常用来在编译后的程序中加入一个时间标志,以区分程序的不同版本;
当要求程序严格遵循ANSIC标准时,标识符__STDC__就会被赋值为1;
当用C++编译程序编译时,标识符__cplusplus就会被定义。

/* ************************************************************************
* Filename: test.c
* Description:
* Version: 1.0
* Created: 2011年07月21日 23时09分30秒
* Revision: none
* Compiler: gcc
* Author: YOUR NAME (),
* Company:
* ************************************************************************/

#include

int main()
{

printf("this file name is:*%s*\n",__FILE__);
printf("this line number is:*%d*\n",__LINE__);
printf("this time is:*%s*\n",__TIME__);
printf("this date is:*%s*\n",__DATE__);
return 0;
}