[splint-discuss] Parse Error on Macro, help

Michael Wojcik Michael.Wojcik at MicroFocus.com
Thu Sep 7 10:26:04 EDT 2006


> From: splint-discuss-bounces at cs.virginia.edu 
> [mailto:splint-discuss-bounces at cs.virginia.edu] On Behalf Of 
> James Dennett
> Sent: Thursday, 07 September, 2006 00:06
> 
> 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.)

And *this* is wrong, per 9899-1990 6.8.3, as discussed earlier; and
Richard noted in a subsequent email that it was wrong.  Empty
parentheses [in the parameter list, ie an empty identifier-list] in a
macro *definition* is allowed in C89/C90.

> > 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.

But *this* is arguably correct.  9899-1990 6.8.3 goes on to say, "If
(before argument substitution) any argument consists of no preprocessing
tokens, the behavior is undefined".

Clearly allowing an empty parameter list in the definition, but
disallowing an empty parameter list when invoking such a function-like
macro, doesn't make much sense.  However, if an implementor interpreted
"any argument" above as including the case of a function-like macro with
an empty parameter list, then it's UB and the implementation could
refuse to translate the TU.

I'd be reluctant, personally, to defend such an interpretation, but the
C90 standard does seem to be ambiguous here and I can see why Tydeman's
DR was useful. 

> 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.

The passage I quoted above seems to be the relevant bit, and IMO the
whole thing hangs on the interpretation of the phrase "any argument" in
it.  Rather than argue over that, though, I suggest we accept the fact
that the issue was sufficiently in doubt for Tydeman to propose a DR and
the committee to accept it; and so sufficiently in doubt that
otherwise-conforming implementations might mistake the intent of the
standard if it did indeed intend to allow an empty argument list for a
function-like macro with an empty parameter list.

(The only other mention of UB in function-like macro replacement is if
the sequence of pp-tokens in the argument list includes sequences that
would otherwise act as preprocessing directives, which clearly doesn't
apply in this case.)

-- 
Michael Wojcik
Principal Software Systems Developer
Micro Focus

michael.wojcik at microfocus.com
9420 Key West Avenue
Rockville, MD 20850
Direct: 517 676 0892
What would you like Micro Focus to do for you? Contribute your view by
visiting
http://www.microfocus.com/CustomerInsight.asp



More information about the splint-discuss mailing list