Can C determine which OS it's being compiled on?

Hello all! I've searched the archives, google, documentation and I can't seem to find any answer regarding my question.

Our code has to be lint free and due to the following lint warning ---> logical expression always true: op "||" <--- we are forced to #include <note.h > (which appears to be Solaris specific) in order to use "NOTE(CONSTCOND) /*CONSTCOND*/" within the code to suppress the above warning. Any ideas on whether or not standard C can determine an OS? Ideally, I'd like C to determine what OS and from there include the header or not based on OS . . . if SunOS, then include note.h, else do not. I know this is far-fetched :o but had to ask. TIA!

Steven

Can you not use a shell script or a makefile to compile?

I don't know what the output from uname gives on your version of Solaris - the last time I did that it was SunOS a very long time ago - so this example uses that string

PLAT=""
uname | grep -q 'SunOS' && PLAT="-DSUNOS"
cc -o somefile $PLAT somefile.c

C code:

/* in C */
#ifdef SUNOS
#include <note.h>
#endif

It compiles on both Linux and Solaris. I've yet to try it on HP or AIX, but I imagine it will work. I've pasted the code just for the sake of anyone searching.

code:

#if defined(solaris)
#include <note.h>
#else
#define NOTE(ignore)
#endif

The answer is yes. It is how source code handles differences between base platforms. Here is a pointer to more information on predefined operating system macros which should help you. Pre-defined Operating System Macros