Is #elif portable?

C

Charles Sullivan

I'm trying to maintain some older C code (FOSS) which has been
patched by various individuals over the years for portability to
multiple Unix-like operating systems, to wit: Linux, SunOS,
Solaris, Free/Open/NetBSD, Mac OS X, AT&T SysV r4, SCO Unix, AIX,
OSF, NextStep.

I want to add some conditionals like this:

#if defined(USECODE_A)
/*use this code */
#elif defined(USECODE_B)
/*use this code */
#elif defined(USECODE_C)
/*use this code */
#elif defined(USECODE_D)
/*use this code */
#else
/*use this code*/
#endif

However although in the existing code there are numerous
"#if/#else/#endif" conditionals with what seems like awkward
nesting, nowhere do I find "#elif" used.

K&R 2nd edition (1988) says #elif is new since the 1978 edition.

How likely is there to be a portability problem if I use #elif ?

Thanks for your advice.

Regards,
Charles Sullivan
 
R

Robert Gamble

I'm trying to maintain some older C code (FOSS) which has been
patched by various individuals over the years for portability to
multiple Unix-like operating systems, to wit: Linux, SunOS,
Solaris, Free/Open/NetBSD, Mac OS X, AT&T SysV r4, SCO Unix, AIX,
OSF, NextStep.

I want to add some conditionals like this:

#if defined(USECODE_A)
/*use this code */
#elif defined(USECODE_B)
/*use this code */
#elif defined(USECODE_C)
/*use this code */
#elif defined(USECODE_D)
/*use this code */
#else
/*use this code*/
#endif

However although in the existing code there are numerous
"#if/#else/#endif" conditionals with what seems like awkward
nesting, nowhere do I find "#elif" used.

K&R 2nd edition (1988) says #elif is new since the 1978 edition.

How likely is there to be a portability problem if I use #elif ?

#elif has been around since the early 1980s. It was supported by
many, if not most, compilers by the late 1980s as it was present in
the ANSI C draft, any Standard conforming implementation will support
it. If you don't care about supporting pre-ANSI compilers there is
nothing to worry about, but if you do then you can't assume #elif will
be available in all cases.

Robert Gamble
 
C

Charles Sullivan

#elif has been around since the early 1980s. It was supported by
many, if not most, compilers by the late 1980s as it was present in
the ANSI C draft, any Standard conforming implementation will support
it. If you don't care about supporting pre-ANSI compilers there is
nothing to worry about, but if you do then you can't assume #elif will
be available in all cases.

Robert Gamble

Thanks Robert. I think I'll go ahead and use it. If anyone squawks
then I'll know there are users with antique compilers who are
still using the software and I can deal with them individually.

Regards,
Charles Sullivan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top