Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Problem Compiling Certain Bad C Code

1 view
Skip to first unread message

Frank Wortner

unread,
Sep 20, 1988, 12:12:34 PM9/20/88
to
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

Eduardo Krell

unread,
Sep 21, 1988, 8:25:42 PM9/21/88
to

>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: ekr...@ulysses.att.com

KP KP

unread,
Aug 1, 2022, 7:10:26 PM8/1/22
to
tattie
0 new messages