structured entry of #if preprocessor commands

Steve Summit scs at adam.mit.edu
Mon Feb 11 07:46:04 AEST 1991


In article <1991Feb10.063915.5476 at ccu.umanitoba.ca>, Jason Smigiel writes:
>Is it common practice not to structure preprocessor commands in ANSI C?
>I looked in the K&R2 reference manual, under A12,(very first paragraph) and
>it states:
> 
>    "Lines beginning with #, perhaps preceded by white space, communicate
>    with this preprocessor."
> 
>  So it seems completely valid to me, I just wanted to know if this was a
>smart thing to do or am I entirely insane?

You're not insane.  However, leading whitespace before
preprocessor directives is a relatively new "innovation."
Older compilers do not allow it, and there are enough of them
around that people tend not to use leading whitespace at all.
Furthermore, those of us who have been using the older compilers
for years are so used to it that nicely indented nested #if's
look, well, pretty weird.  You're correct, though, in thinking
that more nicely structured #if's would be better.

What I can't explain is why the following style, which most old
compilers would accept, has never been widespread (and which
therefore looks equally weird to me):

   #if defined(MSDOS)
   #   if defined(ANSI)
   #   include "ms_ansi.h"
   #   endif
   #else /* not msdos */
   #   if !defined(ATARIST_MWC) && !defined(MAC) && !defined(AMIGA)
   #      ifndef VMS
   #      include <sys/ioctl.h>
   #      endif
   #   include <signal.h>
   #   endif
   #endif

For all the ranting that I and others do about the importance of
good style and clear program layout, there are always these
little hypocrisies.

                                            Steve Summit
                                            scs at adam.mit.edu



More information about the Comp.lang.c mailing list