一、ANSI C标准预定义宏


 

__LINE__:在源代码中插入当前源代码行号;

__FILE__:在源文件中插入当前源文件名;

__DATE__:在源文件中插入当前的编译日期

__TIME__:在源文件中插入当前编译时间;

__STDC__:当要求程序严格遵循ANSI C标准时该标识被赋值为1,表明是标准的C程序;

//__cplusplus:当编写C++程序时该标识符被定义,表明是标准的C++程序。(这个是VC的吧?)

 

MSDN上的解释

Macro
Description

__DATE__
The compilation date of the current source file. The date is a string literal of the form Mmm dd yyyy. The month name Mmm is the same as for dates generated by the library functionasctime declared in TIME.H.

__FILE__
The name of the current source file. __FILE__ expands to a string surrounded by double quotation marks.

__LINE__
The line number in the current source file. The line number is a decimal integer constant. It can be altered with a #line directive.

__STDC__
Indicates full conformance with the ANSI C standard. Defined as the integer constant 1 only if the /Za compiler option is given and you are not compiling C++ code; otherwise is undefined.

__TIME__
The most recent compilation time of the current source file. The time is a string literal of the form hh:mm:ss.

__TIMESTAMP__
The date and time of the last modification of the current source file, expressed as a string literal in the form Ddd Mmm Date hh:mm:ss yyyy, where Ddd is the abbreviated day of the week and Date is an integer from 1 to 31.

 

一个例子:

#include <iostream>
using namespace std;
int main(int argc,char** argv)
{
    cout << "__FILE__ = " << __FILE__ << endl;
    cout << "__DATE__ = " << __DATE__ << endl;
    cout << "__TIME__ = " << __TIME__ << endl;
    cout << "__LINE__ = " << __LINE__ << endl;
    #if defined(__cplusplus)
        cout<<"在此环境中可以编缉和调试标准C++程序。"<<endl;
    #endif
    #if defined(__STDC__)
        cout<<"在此环境中可以编缉和调试标准C程序。"<<endl;
    #endif
    return EXIT_SUCCESS;
}

你可能感兴趣的:(一、ANSI C标准预定义宏)