4

To handle platform specific code between Mac and Windows, WIN32 and APPLE are the terms to use, right?

So, thw code would look like this:

#ifdef _WIN32
    // Windows code
#endif
#ifdef __APPLE__
    // Mac code
#endif

What about Linux ?

How can i do that for all three? right

juanchopanza
  • 223,364
  • 34
  • 402
  • 480
user1417815
  • 445
  • 3
  • 7
  • 16
  • how about `#ifdef __LINUX__`? (Btw `#ifdef _WIN32` won't detect 64-bit Windows!) –  Jun 02 '12 at 17:43
  • 3
    _WIN32 works fine on 64-bit projects. It only says "32" because there used to be a "16". – Hans Passant Jun 02 '12 at 17:44
  • 3
    possible duplicate of [Is there a list of preprocessor defines for various operating systems (and versions)?](http://stackoverflow.com/questions/2990172/is-there-a-list-of-preprocessor-defines-for-various-operating-systems-and-versi) – Hans Passant Jun 02 '12 at 17:47

1 Answers1

6

It's similar:

#ifdef __linux__
    // Linux code
#endif

Since you are going to have either one of these three defined at a time, this should be ok for all three.

List of defines.

P.P
  • 117,907
  • 20
  • 175
  • 238
  • SHouldn't it be __LINUX__ and not __linux__? or that dont matter, btw you didn't tell me if i was doint it right with the others – user1417815 Jun 02 '12 at 17:45
  • lowercase. Different OSes have different names. __linux__ for liux. I updated the answer with a link for others too. – P.P Jun 02 '12 at 17:47