For vs while (was Re: Comparing strings...)
Richard A. O'Keefe
ok at goanna.cs.rmit.oz.au
Mon Oct 22 21:25:56 AEST 1990
In article <8308 at scolex.sco.COM>, seanf at sco.COM (Sean Fagan) writes:
> #define while(cond) for(;cond;)
>
> (I'm sitting here trying to think of any case where this will break
> [no pun intended 8-)] something; I can't think of any, offhand.)
Here's one: do i++; while (p(i));
> If you have something such as
> while () {
> whatever;
> }
> this will be an infinite loop given the macro, but a syntax error otherwise.
In gcc it's a syntax error. In a guide to ANSI C that I have before me, it
says that "a macro argument is ONE or more preprocessing tokens. I think this
was a nasty thing for the committee to do: it is the one thing which has
broken most of my code. Yes, the standard _does_ permit the definition of
macros that look like functions with no arguments:
#define no_arg_mac() stuff
... no_arg_mac() ...
unfortunately old preprocessors that were happy with no tokens in an
argument tended to be unhappy with no arguments in a definition. So I
have to do
#ifdef __STDC__
#define no_arg_mac() stuff
#else
#define no_arg_mac(DUMMY) stuff
#endif
Snarl. (Naturally, I figured out how to do that _after_ I'd added dummy
arguments to the invocations in the files I really cared about. Sigh.)
--
Fear most of all to be in error. -- Kierkegaard, quoting Socrates.
More information about the Comp.lang.c
mailing list