[C++] "standardized" macro's to detect OS?
I find the macro's to detect operating system with an #ifdef confusing, because I see different things being used.
For Windows, is it _WIN32, WIN32, _MSDOS or MSDOS? What about 64-bit Windows, does "WIN32" still work there?
For Linux, is it _GNUC_, UNIX, LINUX, POSIX, or what?
And what is it for Mac? I don't have a Mac to develop on to try it but I might need it one day.
I assume there doesn't really exist any reliable standard for it, but which combination would work best?
Also, do there exist ways to detect with macro's what you're adding to the linker parameters of the compiler? For example, if I link to "boost_filesystem", it could use a boost implementation for browsing files, if not it could use a native one like win32 or posix code or a dummy implementation that says "not supported".
This site has a good listing of predefined macros. As to what the best subsets are to maximize detection reliability, but minimize size, I'll leave that an open question :)
Quote:Original post by mattd
This site has a good listing of predefined macros. As to what the best subsets are to maximize detection reliability, but minimize size, I'll leave that an open question :)
Nice! They list more than enough operating systems in there :)
Very handy.
Actually, you could get some guidance for that 'but which macros' open question by looking at how something like boost does it.
Quote:Original post by mattdI am not sure that is such a good idea - boost has some of the most convoluted platform and feature detection on the planet. Granted, they need it, but it should be complete overkill for a game project.
Actually, you could get some guidance for that 'but which macros' open question by looking at how something like boost does it.
I usually stick with a simple (and so far reliable):
#if defined( WIN32 )#elif defined( __APPLE__ )#else /* some flavour of unix */#endif
Of course, if you want to detect minor platforms, then you need to do a bit more work.
Quote:Original post by swiftcoder
I am not sure that is such a good idea - boost has some of the most convoluted platform and feature detection on the planet.
Quote:I usually stick with a simple (and so far reliable):
Did you actually look at the header file that he linked to? What boost does isn't very different from what you do, except that it handles more platforms than you do.
Quote:Original post by SiCraneYes, but blindly copying from that header without familiarity for the platforms involved is dangerous. For instance, their Mac path supports classic-mac as well as OS X, which is something that one won't notice without mac experience, and almost certainly isn't what one intends.
Did you actually look at the header file that he linked to? What boost does isn't very different from what you do, except that it handles more platforms than you do.
That's seems like a very different statement than "the most convoluted platform and feature detection on the planet."
Quote:Original post by SiCraneThat header file is just the tip of the iceberg. There are detection headers for each platform, plus feature detection for endianess, integer types, system header files, etc.
That's seems like a very different statement than "the most convoluted platform and feature detection on the planet."
But, to be fair, I did overstate that a little - sarcasm is a dangerous thing on the internet [smile]
By more than a little if you just after you say it you then suggest to do things the exact same way.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement