3

Possible Duplicate:
the role of #ifdef and #ifndef

Does

#ifndef _WIN32 

instruct the cpp to omit the code for 32 bit windows platform ?

Community
  • 1
  • 1
KernelMonk
  • 311
  • 1
  • 5
  • 9

3 Answers3

6

#ifndef _WIN32 tells the pre-processor to include the code below it till a corresponding #endif, if _WIN32 is not defined.

#ifndef _WIN32
#define STR1 "Some String"
#endif

The macro STR1 will get included if _WIN32 is not defined and will not get included if _WIN32 is defined. Please note that _WIN32 is a system defined macro. Generally, the code which is not meant for Windows platform or which is generic and cannot be compiled in Windows is placed under such #ifndef _WIN32 macros.

The MSDN page says _WIN32 will be defined by default for all 32 bit and 64 bit builds.

Jay
  • 24,173
  • 25
  • 93
  • 141
1

This directive means "don't include this code when _WIN32 macro defined". If you define macro _WIN32 only when compile for the Win32 then this code "instruct the cpp to omit the code for 32 bit windows platform".

Dmitry Poroh
  • 3,705
  • 20
  • 34
0

Well it is a preprocessor directive. It is called compilation constants.

Compiler will consider the piece of code under those #ifndef if the compilation constant(such as, _WIN32) is not defined.

I believe above explanation will help you resolving your query.

To be more specific,

#ifndef _WIN32

...
...
...
some code
...
...
...

#endif

here if you have not defined _WIN32 (such as #define _WIN32) then the code within that #if...#endif will be compiled.

hope it helps.

Jay
  • 24,173
  • 25
  • 93
  • 141
Kinjal Patel
  • 405
  • 2
  • 7