Generally, you'll use macros or the like. This can get complicated quickly, so generally you'll use your build system for this. The syntax would be expressed like this:
1 2 3 4 5 6 7 8 9
#ifdef OS_WINDOWS
// windows specific code
#elifdef OS_MACOSX
// mac specific code
#elifdef OS_LINUX
// assume linux
#else
#error Unrecognised operating system!
#endif
Then, you simply compile the code based on your operating system, for example on a Debian machine with GCC you might do:
Compilers also often provide their own predefined macros telling you what operating system you are using, but due to the fact that they aren't standardized they all seem to use different ones, and it can be a pain to keep track of.