Using the standard pre-defined and compiler specific macros C++ code sample

 

Compiler: Visual C++ Express Edition 2005

Compiled on Platform: Windows XP Pro SP2

Header file: Standard

Additional project setting: Set project to be compiled as C++

Project -> your_project_name Properties -> Configuration Properties -> C/C++ -> Advanced -> Compiled As: Compiled as C++ Code (/TP)

Other info:

To do: Using the standard pre-defined and compiler specific macros in C++ programming, extracting some application information

To show: How to use the standard pre-defined and compiler specific macros in C++ programming

 

// macros in C++ example

#include <iostream>

using namespace std;

 

int main(void)

{

cout<<"Let test the standard pre-defined and compiler specific..."<<endl;

cout<<"\nPredefined macro __LINE__ : "<<__LINE__<<endl;

cout<<"Predefined macro __FILE__ : "<<__FILE__<<endl;

cout<<"Predefined macro __TIME__ : "<<__TIME__<<endl;

cout<<"Predefined macro __DATE__ : "<<__DATE__<<endl;

cout<<"Some compiler specific _CPPLIB_VER: "<<_CPPLIB_VER<<endl;

cout<<"Some compiler specific _M_IX86: "<<_M_IX86<<endl;

cout<<"Some compiler specific _CPPLIB_VER: "<<_CPPLIB_VER<<endl;

cout<<"Some compiler specific _CPPRTTI: "<<_CPPRTTI<<endl;

cout<<"Some compiler specific _WIN32: "<<_WIN32<<endl;

return 0;

}

 

Output examples:

 

Let test the standard pre-defined and compiler specific...

Predefined macro __LINE__ : 8

Predefined macro __FILE__ : f:\vc2005project\myaddr\myaddr\myaddr.cpp

Predefined macro __TIME__ : 20:32:40

Predefined macro __DATE__ : Nov 16 2006

Some compiler specific _CPPLIB_VER: 405

Some compiler specific _M_IX86: 600

Some compiler specific _CPPLIB_VER: 405

Some compiler specific _CPPRTTI: 1

Some compiler specific _WIN32: 1

Press any key to continue . . .

 

Let test the standard pre-defined and compiler specific...

 

Predefined macro __LINE__ : 8

Predefined macro __FILE__ : c:\amad\myprog\myprog\myechosrc.cpp

Predefined macro __TIME__ : 10:52:55

Predefined macro __DATE__ : Nov 9 2011

Some compiler specific _CPPLIB_VER: 503

Some compiler specific _M_IX86: 600

Some compiler specific _CPPLIB_VER: 503

Some compiler specific _CPPRTTI: 1

Some compiler specific _WIN32: 1

Press any key to continue . . .

 

 

C and C++ Programming Resources | C & C++ Code Example Index