[comp.os.minix] Complaints about conditional compilation

dcd@tc.fluke.COM (David Dyck) (06/07/89)

In article <2775@munnari.oz> muller@munnari.oz (Paul Muller) writes:
>
>.......[deleted]
>
>......... If you
>were a student you wouldn't fancy wading through all those #ifdefs for two
>days just to find you made a mistake early on in the code and that's why
>none of what the lecturer is saying fits together. I am a student and find
>nothing more annoying than conditional compilation, it ruins your day and
>often clouds the purpose of the code.
>

To those who do not wish to read conditional compilation directives
there is a great program that was posted to comp.sources.unix a while back.
It is archived in "Volume 3 (Ends Feburary, 1986)" with the index
"scpp        (2 parts) A selective C preprocessor - clean up your C files."

I DID NOT WRITE IT.  Credit goes to
Brad Needham
Tektronix, Inc.
...decvax!tektronix!tekig4!bradn


Here is the manual page.

SCPP(1)                  USER COMMANDS                    SCPP(1)

NAME
     scpp - selective C preprocessor

SYNOPSIS
     scpp [ -Mmacro ] [ -Dmacro ] [ -Dmacro=def ] [ -C ]
          [ -Iincdir ] [ file... ]

DESCRIPTION
     Scpp concatenates the input files (or reads standard-in,  if
     no  file  is given), interprets all references to given mac-
     ros, leaving the rest of the file(s) unaltered, then  writes
     the  result to standard-out.  It is helpful in removing con-
     ditionally compiled code or misleading macros from a file.

     The file name "-" refers to standard-in.

     The following options are available.  Each option can appear
     as frequently as desired.

          -M   Interpret all references to the given macro. Macro
               can   be   either   a   single  macro  name  or  a
               whitespace-separated list  of  macro  names  (e.g.
               -MMAXINT   or   -M"MAXINT  MININT  INTWID").   All
               occurrences of the macro and all instances of  the
               intrinsic  macro  "defined()"  referring  to  this
               macro are expanded.  All  preprocessor  directives
               referring to this macro (except #if) perform their
               usual function and do not appear  in  the  output.
               #if directives are interpreted only if their value
               is not dependent on macros which  are  not  to  be
               interpreted.

          -D   Define the macro to have the value def, or "1"  if
               no  def is given.  Unlike the C preprocessor, scpp
               does not implicitly  define  certain  macros  that
               describe the environment in which the code will be
               running (e.g. "vax" or "unix").  -D implies -M.

          -C   Preserve comments and  whitespace  in  interpreted
               macro definitions.  Normally, comments and leading
               and trailing whitespace are stripped  from  inter-
               preted macro definitions.

          -I   Add incdir  to  the  list  of  directories  to  be
               searched  for include files.  Scpp searches direc-
               tories in the same order as the C preprocessor: if
               the  include filename is enclosed in double-quotes
               ("...") rather than  angle-brackets  (<...>),  the
               directory  containing  the current file being pro-
               cessed; the  directories  given  by  -I,  left-to-
               right; the standard directory, /usr/include.

AUTHOR
     Brad Needham, Tektronix, Inc.

SEE ALSO
     cc(1).

BUGS
     Very long identifiers (those over 100 characters long)  will
     crash scpp.

     Because scpp interprets only the given macros,  the  meaning
     of some code will change.  E.g. "scpp -MBOO" of
          #define BOO hello,there
          #define twopar(a,b) a b
          twopar(BOO,folks)
     will generate
          #define twopar(a,b) a b
          twopar(hello,there,folks)
     causing an argument mismatch when the output is compiled.

     Because uninterpreted "#if"s, "ifdef"s, and "ifndef"s,  have
     no  effect  on  the output, the following example, when pro-
     cessed via "scpp -MLEFT", will  generate  an  error  message
     complaining about multiple definitions of "LEFT".
          #ifdef ZULU
          #define LEFT 20
          #else
          #define LEFT 347
          #endif

     The C preprocessor macros "__FILE__" and "__LINE__" have  no
     special meaning to scpp.