By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,418 Members | 1,088 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,418 IT Pros & Developers. It's quick & easy.

Is #elif portable?

P: n/a
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


Feb 24 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On Feb 23, 9:40 pm, Charles Sullivan <cwsul...@triad.rr.comwrote:
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

Feb 24 '07 #2

P: n/a
On Fri, 23 Feb 2007 19:17:10 -0800, Robert Gamble wrote:
On Feb 23, 9:40 pm, Charles Sullivan <cwsul...@triad.rr.comwrote:
>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
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
Feb 24 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.