[gnu.gcc.bug] Problem Compiling Certain Bad C Code

frank@morgan.com (Frank Wortner) (09/20/88)

I've run into a number of problems compiling certain bits of C code.
GCC reports syntax errors on files which pass through CC without
problems.  In investigating this problem, I found that some programs
and headers contain constructs like this:

-------------

#ifdef COMMENT

This is a really strange way to make a comment, wouldn't you say?

#endif

-------------

GCC will report an unterminated character constant in the code
fragment above, regardless of whether or not COMMENT is defined.
The fix is to turn this pseudo-comment into a real comment.

In some cases comments like the above also exist in code to force
deliberate errors if a certain required macro is not defined.

-------------

#ifndef MEM_SIZE

You forgot to define MEM_SIZE, didn't you?

#endif

-------------

Since this nasty device can appear in older (or just plain uglier)
source code, you may want to issue an anti-brain-damage warning in GCC
documentation.

					Frank

ekrell@hector.UUCP (Eduardo Krell) (09/22/88)

In article <8809201612.AA10674@s2.Morgan.COM> frank@morgan.com writes:

>GCC will report an unterminated character constant in the code
>fragment above, regardless of whether or not COMMENT is defined.

This actually comes from cpp, not gcc. The reason is that gcc (and its
cpp) are ANSI C by default, which means that cpp has to tokenize to
correctly behave as an ANSI C cpp. In other words, it has to parse
the text being #ifdef'ed out.

If you use the -traditional flag, this code will compile OK.
    
Eduardo Krell                   AT&T Bell Laboratories, Murray Hill, NJ

UUCP: {att,decvax,ucbvax}!ulysses!ekrell  Internet: ekrell@ulysses.att.com