Article View: comp.std.c
Article #4749Re: Are macros expanded within unused macro arguments?
From: Tanmoy Bhattacharya
Date: Fri, 02 Feb 1996 18:16
Date: Fri, 02 Feb 1996 18:16
45 lines
2511 bytes
2511 bytes
In article <4es8rp$98n@usenet.pa.dec.com> diamond@tko.dec.com (Norman
Diamond) writes:
<snip>
>>Is the following program legal?
>>#define foo(unused)
>>#define bar(x,y)
>>foo(bar(1))
>I read it as being legal.
Mr. Bhattacharya, I am shocked.
>>Excerpt from "6.8.3.1 Argument substitution"
>> After the arguments for the invocation of a function-like macro have
>> been identified, argument substitution takes place. A parameter in the
>> replacment list, ..., is replaced by the corresponding argument after
>> all macros contained therein have been expanded. Before being
>> substituted, each argument's preprocessing tokens are completely macro
>> replaced ... .
>You gave the reason :-) The quoted text seems to imply the following order:
> 1) Identify parameters
[...]
I think there's a preceding order as well:
0) constraints checked, including ANSI Classic section 3.8.3, page 90
lines 14 to 15: "The number of arguments in an invocation of a
function-like macro shall agree with the number of parameters in
the macro definition, and [...]"
I think the important question is whether bar is ever invoked here. I
read it as legal because I interpreted the wording as macros in
parameters are invoked only if they appear in the replacement list not
preceded by # or ## and not followed by ##; or if they are otherwise
invoked during rescanning.
Cheers
Tanmoy
--
tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
<http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
fax: 1 (505) 665 3003 voice: 1 (505) 665 4733 [ Home: 1 (505) 662 5596 ]
Technical Details
Message-ID:
<TANMOY.96Feb2111614@qcd.lanl.gov>Path:
arc1-ca.pugleaf.net!newshost.lanl.gov!tanmoyReferences:
<DM3MC3.Atv@scr.siemens.com> <TANMOY.96Feb1102025@qcd.lanl.gov> <4es8rp$98n@usenet.pa.dec.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!newshost.lanl.gov!tanmoy From: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya) Newsgroups: comp.std.c Subject: Re: Are macros expanded within unused macro arguments? Date: 02 Feb 1996 18:16:14 GMT Organization: Los Alamos National Laboratory Message-ID: <TANMOY.96Feb2111614@qcd.lanl.gov> References: <DM3MC3.Atv@scr.siemens.com> <TANMOY.96Feb1102025@qcd.lanl.gov> <4es8rp$98n@usenet.pa.dec.com> NNTP-Posting-Host: qcd.lanl.gov Mime-Version: 1.0 Content-Type: text In-reply-to: diamond@tko.dec.com's message of 2 Feb 1996 05:52:57 GMT