Another #pragma message usage program example

 

Compiler: Visual C++ Express Edition 2005

Compiled on Platform: Windows XP Pro SP2

Header file: Standard

Additional library: none/default

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 (/TC)

Other info: none

To do: Using the #if...#endif and #pragma message for conditional compilation

To show: How to use the #if...#endif and #pragma message in C/C++ programming

 

// More on #pragma directives

#include <stdio.h>

 

#if _M_IX86 != 500

#pragma message("Non Pentium processor build")

#endif

 

#if _M_IX86 == 600

#pragma message("but Pentium II above processor build")

#endif

 

#pragma message("Compiling " __FILE__)

#pragma message("Last modified on " __TIMESTAMP__)

 

int main(void)

{

return 0;

}

 

Output example:

 

You can see the following statements in the output window after the compilation.

 

1>------ Build started: Project: myaddr, Configuration: Debug Win32 ------

1>Compiling...

1>myaddr.cpp

1>Non Pentium processor build

1>but Pentium II above processor build

1>Compiling f:\vc2005project\myaddr\myaddr\myaddr.cpp

1>Last modified on Thu Nov 16 20:21:48 2006

1>Linking...

1>Embedding manifest...

1>Build log was saved at "file://f:\vc2005project\myaddr\myaddr\Debug\BuildLog.htm"

1>myaddr - 0 error(s), 0 warning(s)

========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

 

 

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