[splint-discuss] Parse Error on Macro, help
Richard A. O'Keefe
ok at cs.otago.ac.nz
Wed Sep 6 19:38:40 EDT 2006
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?) 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.
> 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.
More information about the splint-discuss
mailing list