IUBio GIL .. BIOSCI/Bionet News .. Biosequences .. Software .. FTP

Portable software II

David Mathog mathog at seqvax.caltech.edu
Tue Feb 14 13:29:00 EST 1995


Just a few more gripes after a hard day porting.  Common folks - a little
rigor up front would save a ton of work...

1.  Do NOT use any of the following to indicate OSF/1

    #ifdef ALPHA
    #ifdef alpha
    #ifdef __ALPHA
    #ifdef __alpha
    #ifdef axp
    etc.

    Right now the AXP chips run OSF/1 & VMS & WNT.  A Linux
    version is in the works too.  So trying to mark OSF/1 by specifying the
    chip is a *poor* idea.  It's possible that OSF1 might run someday
    on another processor too.  Solaris runs on multiple platforms, so
    does WNT.  Additionally, OS's that run on multiple platforms need
    a symbol for any platform (shared things, like directory syntax) and
    for each platform (for data types which may have different length.)

    Something along the following lines would be good:

    #ifdef axpOSF       /* OSF/1 on AXP */
    #ifdef axpWNT       /* WNT on AXP */

    #ifdef axpVMS       /* VMS on AXP */
    #ifdef vaxVMS       /* VMS on VAX */
    #ifdef anyVMS       /* VMS on any platform */

    #ifdef riscSOLARIS  /* Solaris on RISC */
    #ifdef intelSOLARIS /* Solaris on Intel */
    #ifdef anySOLARIS   /* Solaris on any platform */

    #ifdef intelLINUX   /* Linux on Intel */
    #ifdef axpLINUX     /* Linux on AXP */
    #ifdef anyLINUX     /* Linux on any platform */

2.  Ok, you can't know ahead of time what platform somebody is going to
    port your software to, but just think how much fun it is to 
    dig through a nested set of ifdefs that look like the following in 
    order to figure out where to patch in for a new OS:

    #if defined(A) || defined(B)
    #if !defined(C)
    #else
    #if OPTION1
    #else
    #endif
    #endif
    #else
    #if OPTION1
    #if defined(D)
    #else
    #endif
    #else
    #endif
    #endif

    I suggest that developers not worry quite so much about saving space
    and expand these things so that they are easier to read and understand.
    In particular, ditch the unqualified #else's - it's way too easy to
    drop through one of these.  For instance

    /*Stuff common to a couple of platforms*/
    #if defined(PlatformA) || defined(PlatformB) || defined(PlatformC)
    #endif
    /*Stuff specific to each platform - notice, no #else */
    #if defined(PlatformA)
    #endif
    #if defined(PlatformB)
    #endif
    #if defined(PlatformC)
    #endif

3.  I'd also like to point out that if more of you would use the ANSI C
    switches on your compilers you'd find one heck of a lot fewer
    #ifdefs in your code! 

    Developers, please take a minute to check your makefiles.  Is the "ANSI
    C compliant" switch set?  Do NOT assume that just because you have an
    ANSI C compiler that it is running in ANSI C mode - every C compiler
    I've  seen defaults to a "relaxed" mode, and none of them have the
    *same* relaxed mode.

    If you are writing in C, but not checking for ANSI C compliance,
    please post here your rationale for writing nonstandard, nonportable
    code. 

Regards,

David Mathog
mathog at seqvax.bio.caltech.edu
Manager, sequence analysis facility, biology division, Caltech 




More information about the Bio-soft mailing list

Send comments to us at archive@iubioarchive.bio.net