Voguemaster <[EMAIL PROTECTED]> writes:

> Hi list,
> 
> I'm writing a portable set of classes for a network application
> (the classes will be reused) for Win32 and Linux. I don't wish to
> use external libraries since those are simple primitives.
> 
> I'm generally using some #ifdef statements (although I've minimized their
> use using a header file for a class and 2 source files (one per platform).
> 
> Now, as it seems, #ifdef doesn't support something like this:
> 
> #if defined(..)
> ..
> #elif defined(..)
> ..
> #endif
> 
> I only recently discovered the GNU preprocessor actually supports those
> (hehe, dumb, i know..) but I was wondering if anyone knows the earliest
> version of Linux in which this set of directives is supported on.
> (I would like to be able to compile this thing on RH6.2, for example).
> 
> My biggest concern is portability. I'd like to make sure the code compiles
> nicely on any system this thing is going to be compiled on :)

The only reason it can fail to compile is that some old *traditional*
C compilers may not support #elif.  This is ISO C, and if you find a
modern preprocessor that does not support it, it should be taken out
and shot. ;-)

I cannot check that is compiles on RH6, but it should, with a
compliant compiler. 

The following code

#if defined(FOO)
static int x = 1;
#elif defined(BAR)
static int x = 2;
#else
static int x;
#endif

int main(void) { return x; }


compiles cleanly with 

gcc -O2 -pedantic -ansi -W -Wall 

and runs correctly in all cases on RH7.3, with gcc 2.96-113 and gcc
3.2.3. No problems with the corresponding versions of g++, either.

-- 
Oleg Goldshmidt | [EMAIL PROTECTED]

=================================================================
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]

Reply via email to