<p>I need my code to do different things based on the operating system on which it gets compiled. I'm looking for something like this:</p>

<pre><code>#ifdef OSisWindows
// do Windows-specific stuff
#else
// do Unix-specific stuff
#endif
</code></pre>

<p>Is there a way to do this? Is there a better way to do the same thing?</p>

Some compilers will generate #defines that can help you with this. Read the compiler documentation to determine what they are.
MSVC
defines one that's
```
__WIN32__
```
,
GCC
has some you can see with
```
touch foo.h; gcc -dM foo.h
```