473,385 Members | 1,958 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Is #elif portable?

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
2 2582
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

131
by: pemo | last post by:
Is C really portable? And, apologies, but this is possibly a little OT? In c.l.c we often see 'not portable' comments, but I wonder just how portable C apps really are. I don't write...
13
by: Jim | last post by:
Could somebody tell me why I need the "elif char == '\n'" in the following code? This is required in order the pick up lines with just spaces in them. Why doesn't the "else:" statement pick this...
3
by: lostsoul | last post by:
Hi All, I am new in learning programming. I am very lost. I read all of the chapters over and over again and I am still lost. I have the program below that I need to modify it to add hint to it...
2
by: juan-manuel.behrendt | last post by:
Hello together, I wrote a script for the engineering software abaqus/CAE. It worked well until I implemented a selection in order to variate the variable "lGwU" through an if elif, else...
409
by: jacob navia | last post by:
I am trying to compile as much code in 64 bit mode as possible to test the 64 bit version of lcc-win. The problem appears now that size_t is now 64 bits. Fine. It has to be since there are...
7
by: Shawn Minisall | last post by:
I just learned about if, then elif statements and wrote this program. The problem is, it's displaying all of the possibilities even after you enter a 0, or if the fat grams are more then the total...
2
bvdet
by: bvdet | last post by:
We are parametrically attaching a bent plate object to the side of a building column for support of a skewed beam. Given a relative rotation between the column and beam and which side of the column...
6
by: Neil Webster | last post by:
Hi all, I'm sure I'm doing something wrong but after lots of searching and reading I can't work it out and was wondering if anybody can help? I've got the following block of code: if a >= 20...
2
by: Kid Programmer | last post by:
Hello guys. I was wondering if you could use a thing in python in java. That is an elif statement. It is saying else if. It will execute a block of code if the condition in the if statement is...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.