[splint-discuss] Parse Error on Macro, help
James Dennett
jdennett at acm.org
Thu Sep 7 00:05:46 EDT 2006
Richard A. O'Keefe wrote:
> I wrote:
> > Note 1: having empty parentheses in a macro definition is technically
> > undefined in C89. (I'm not sure, it might be illegal.)
>
> James Dennett <jdennett at acm.org> queried this:
> Are you sure? It's well-defined in C++98, which is almost
> identical to C89/90 in terms of preprocessing. An empty
> parameter name is illegal, but the case of () defines a
> function-like macro with no arguments. AFAIK this is a
> moderately common, strictly conforming, technique.
>
> Over the years I have owned three copies of the ANSI C standard
> (two of them copies of the Australian edition, one of them the
> infamous Herbert Schildt edition). All of them have walked out
> of my office. So it's hard to check. (Now that C89 is no longer
> an official standard, why isn't the standard available free over
> the net?)
I don't know if a PDF version has ever been created, or if the original
source even exists anywhere. ISO presumably has no interest, considering
it obsolete now that C99 exists.
> Fortunately, WG14 have kept an archive, which you can find on
> the net, and it turns out that my recollection was 100% correct.
>
> Allowing an empty argument list for a function-like macro was a
> CHANGE from C89 to C99. It was proposed by Fred J. Tydeman on 1995-01-09.
> Empty parentheses on a macro really truly were officially undefined
> behaviour, and he knew of a compiler which complained.
>
> He was talking about empty *actual parameters*, but the two are related.
> There is no point in writing
> #define FOO() ...
> unless you mean to invoke it as
> ... FOO() ...
> and the latter really was undefined behaviour caught by at least one
> compiler. I'm pretty sure the definition was undefined behaviour as well.
>
>
I'd dearly love to see C90; I've re-read C++98, which was intended to
have the same preprocessing behaviour as C90 except in some simple ways,
and that certainly makes it well-defined. (I implemented my
preprocessor based on that specification.)
> > Note 3: having empty parentheses in a macro call is technically
> > undefined in C89. (I'm not sure, it might be illegal.)
>
> It's required to use a function-like macro with no arguments, I
> believe.
>
> So it may be, but you still weren't allowed to do it in C89.
>
If so, this seems to be a case where the standard doesn't match existing
practice,
so it's a good thing that C99 addressed it.
Maybe Michael Wojcik (who apparently has the C90 text to hand) could be
kind enough to check the rules for macro replacement to confirm whether
they fail to define the behaviour for an empty actual parameter list.
(And for completeness: this is of course separate from the case of an
empty argument (aka "actual parameter"), which was certainly not allowed
in C90 or C++98, but is allowed in C99 and will almost certainly be
allowed in C++0x.)
-- James
More information about the splint-discuss
mailing list