Re: Distinguish OS at compile time
* JCR:
Hello,
I need to write somethign like
if WINDOWS
do that
if MAC
do this
Any Macro that can do the job? Should it be compiler specific?
In addition to Robbie Hatley's replies, see <url:
http://predef.sourceforge.net/preos.html> for a list of such macros.
Also, an alternative and often better scheme is to provide platform
specific implementation files, place them in their own per-platform
directory, and select the relevant one at build-time or even
installation time. This moves the issue from being a language issue to
being a build-tools or installation-tools issue, and provides more clean
and maintainable code. However, that doesn't work nearly so well with
compiler-specific code, because you don't want to duplicate essentially
the same code (which would reduce instead of increase maintainability).
Thus, for compiler-specific code some macros like those above can be
necessary, although their effect should (ideally) be centralized, not
peppered around in source files; relevant compiler-detection macros are
listed at <url: http://predef.sourceforge.net/precomp.html>.
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?