Why does the preprocessor process code in #if 0 ?

Paul D. Smith psmith@baynetworks.com
Thu Sep 30 23:56:00 GMT 1999


%% Chirayu Patel <chirayu@elwing.trillium.com> writes:

  cp> cc -E (on solaris) reports a error when I compile this program.
  cp> -----------------------
  cp> #include <stdio.h>
  cp> main ()
  cp> {
  cp> #if 0
  cp>    char a[]={"lkjfg
  cp> lskdjfg"};
  cp> #else
  cp>    char a[]={"lkjfg
  cp> lskdjfg"};
  cp> #endif
  cp> }
  cp> -------------------------

I'm at home and don't have my standard, but I _think_ newlines are
allowed in constant strings without escaping backslashes... which means
that a compiler that complains about this isn't conforming to the ANSI C
standard.  I'll check tomorrow if someone doesn't correct me before then.

Note that that code often wasn't legal with many pre-ANSI, K&R
compilers/preprocessors.
 
  cp> If I change the second declaration of a[]  to
  cp>     char a[]={"lkjfg\
  cp> lskdjfg"};    
  cp> cc -E dosent report any errors. This means cc is able to
  cp> preprocess the code in #if 0.

I don't have any idea where you're getting tha conclusion from.  You
change the second one, in the "#else", and the error goes away.  How
does that mean that cc is preprocessing the code in #if 0?

-- 
-------------------------------------------------------------------------------
 Paul D. Smith <psmith@baynetworks.com>         Network Management Development
 "Please remain calm...I may be mad, but I am a professional." --Mad Scientist
-------------------------------------------------------------------------------
   These are my opinions---Nortel Networks takes no responsibility for them.



More information about the Gcc-help mailing list