tags:

views:

44

answers:

3

Hi

I want to undefine variable when compiling on SunOS. Therefore, i tried to put

#ifdef SunOS
#undef FOO
#endif

but it does not work. The problem is in #ifdef sunos ? Should i declarate it, or complier do it by itself ?

regards S.

+2  A: 

Your compiler will include a number of variables predefined. See your compiler documentation to find out what that list is.

If you're trying to make a piece of software buildable on multiple (unixlike) platforms, then take a look at autoconf. It has a bit of a learning curve, but pays off very handsomely in the long term.

Addition: Also, your compiler might have a way of listing the predefined macros. For example, using gcc, touch foo.h; cpp -dM foo.h produces a list of all of then, which comes to 119 with gcc on OS X. But the documentation will probably give some indication of that compiler's recommended macros for this (but autoconf remains a better technique for this in general).

Norman Gray
A: 

There's nothing wrong with that, cpp accept that fragment just fine. What's the problem you're seeing?

ShiDoiSi
+1  A: 

I don't know of any compilers for Solaris that predefine SunOS for you.

The Sun compilers list the macros they predefine in the 'cc' man page under the -D option description, including __sun and __SunOS_5_10 (for uname -r of "5.10"), but not just plain SunOS.

alanc