[splint-discuss] Parse Error on Macro, help
Richard A. O'Keefe
ok at cs.otago.ac.nz
Wed Sep 6 22:52:01 EDT 2006
I made two claims, one of which was wrong and one of which was right:
(1) defining a macro with () was not defined in C89 [wrong].
(2) invoking a macro with () was not defined in C89 [right].
Recall that
> 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.
So we had the more than odd situation that apparently you were allowed
to define an argumentless function-like macro but you weren't allowed to
invoke it with no arguments.
Terry Colligan <terry-splint at tenberry.com>, who should
speak with authority, tries to have it both ways:
It is (and was) clearly necessary to allow macros to replace
functions, something which has been in C for a long time.
True, but not really relevant. It was NOT necessary to allow an
argumentless DEFINITION to get that effect. If empty arguments
had been legal, then
#define foobar(dummy) (1+1)
...
dummy()
would have been legal.
It *is* clearly in the X3.159-1989 standard, in section 3.8.3.
Is there any way you could talk ANSI into making the old superseded standard
available on the web? As I noted, I've spent several hundred dollars over
the years buying copies that have subsequently disappeared from my office,
so I can't check this for myself.
> 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() ...
Yes! Exactly.
> and the latter really was undefined behaviour caught by at least one
> compiler.
(A) Then that compiler was not conforming to the 1989 standard.
...
(B) What C99 upgraded from a common extension to part of the standard was
the possiblility of empty actual arguments.
And that's where he tries to have it both ways.
(A) is a statement that "the latter" (that is, an INVOCATION of a macro
with an empty argument) conformed.
(B) is a statement that it didn't (it used to be a "common extension",
like three-argument main(), not "part of the standard").
The description is relentlessly and excessively terse, but that was one
of our goals -- to be as brief as possible so as to reduce the chance of
the standard being self-conflicting. Personally, I think we went overboard
and made the standard much harder to read as a result.
The C89 standard wasn't a bad read. In fact, compared with the C++
standard, it was an *excellent* read. (Mind you, compared with
the C++ standard, what isn't?)
> So it may be, but you still weren't allowed to do it in C89.
Yes, you were -- at least in any conforming compiler.
No, you have confirmed, in your statement
(B) What C99 upgraded from a common extension to part of the standard was
the possiblility of empty actual arguments.
that invoking a macro with empty actual parameters was *not* required of
conforming compilers.
Thank you for confirming that.
More information about the splint-discuss
mailing list