views:

150

answers:

4

like is there a:

#ifdef WINDOWS
// do stuff
#else
// linux stuff
#endif

??

A: 

It depends on what files are you using.

The compiler itself doesn't have such a flag, but it is common to have such a define in the operating system's SDK.

For example, the CRT has a Win32 define, which affects how it is compiled.

Am
+6  A: 

The _WIN32 is always defined on Windows platform, checkout the predefined macros.

Zoran Regvart
It is defined only if you include a certain file in your project, or using Visual Studio.
Am
Although I seem to remember having a bit of a surprise once that the compiler for the Symbian emulator defined either _WIN32 or something like it. Sort of made sense, the emulator does run on Windows after all, but we didn't actually want our Win32-specific clauses to apply...
Steve Jessop
The _WIN32 macro is defined by the Microsoft C Compiler (cl.exe), it requires no additional #includes.
Zoran Regvart
A: 

I'm not entirely sure I understand the question but yes, you can do this. Obviously, you need to tell the compiler you're compiling on Windows (or operating system x) at compile time. I've seen a similar approach used for bit size of things like integers.

azp74
+5  A: 

This is the most complete table I know of. http://predef.sourceforge.net/precomp.html

Chris H
+1: Great link!
tur1ng
Superb link, thanks ;)
Zoran Regvart
+1 from me for that link! Nice find! :)
tommieb75