
March 14th, 2006, 02:55 PM
|
|
|
object-like macro used like function-like macro
Hi all,
Is this valid? I do not find the case in the standard:
void foo( int ) {}
#define FOO foo
int main()
{
FOO(0);
return 0;
}
Kind regards,
Patrick
|

March 14th, 2006, 03:05 PM
|
|
|
Re: object-like macro used like function-like macro
Patrick Kowalzick wrote:[color=blue]
> Is this valid? I do not find the case in the standard:
>
> void foo( int ) {}
>
> #define FOO foo
>
> int main()
> {
> FOO(0);
> return 0;
> }[/color]
I am fairly perplexed as to your statement about not finding this "case in
the standard". Did you expect to find precisely this code or any other
explanation to make this legal or not? Where in the Standard did you
look? 'FOO' is replaced with 'foo' in the code _following_ the definition
of 'FOO' macro. Once the preprocessor is done with the code, you get
"void foo(int){}int main(){foo(0);return 0;}"
(I left the spaces where needed to separate the preprocessor tokens).
What's invalid about that code?
And what is "object-like macro" you're referring to in your subject line?
V
--
Please remove capital As from my address when replying by mail
|

March 14th, 2006, 03:05 PM
|
|
|
Re: object-like macro used like function-like macro
> Hi all,[color=blue]
>
> Is this valid? I do not find the case in the standard:
>
> void foo( int ) {}
>
> #define FOO foo
>
> int main()
> {
> FOO(0);
> return 0;
> }[/color]
ARGH. I found my problem. Sorry, really stupid. It was something like:
#ifdef THIS_IS_NOT_DEFINED
#define FOO foo
#else
#define FOO()
#endif
- rather ugly.
Thanks,
Patrick
|

March 14th, 2006, 03:15 PM
|
|
|
Re: object-like macro used like function-like macro
Hello Victor,
[color=blue]
> I am fairly perplexed as to your statement about not finding this "case in
> the standard".[/color]
Sorry to be unprecise. What I do not find is, how a macro expansion is
carried out. And even if my problem was a rather stupid one (see other
post), I do not find the necessary paragraphs for the expansion rules.
[color=blue]
> Where in the Standard did you look?[/color]
Chapter 16.
[color=blue]
> And what is "object-like macro" you're referring to in your subject line?[/color]
Object-like and function-like macro is mentioned in 16.3p2,3.
Thanks,
Patrick
[color=blue]
> V
> --
> Please remove capital As from my address when replying by mail[/color]
|

March 14th, 2006, 03:25 PM
|
|
|
Re: object-like macro used like function-like macro
Patrick Kowalzick wrote:[color=blue]
> Hello Victor,
>
>[color=green]
>>I am fairly perplexed as to your statement about not finding this "case in
>>the standard".[/color]
>
>
> Sorry to be unprecise. What I do not find is, how a macro expansion is
> carried out. And even if my problem was a rather stupid one (see other
> post), I do not find the necessary paragraphs for the expansion rules.[/color]
16.3/8 and 16.3/9. I am surprised you didn't find it, considering that
you read 16.3 apparently quite carefully.
[color=blue][color=green]
>>Where in the Standard did you look?[/color]
>
>
> Chapter 16.[/color]
Yep, it's there alright.
[color=blue][color=green]
>>And what is "object-like macro" you're referring to in your subject line?[/color]
>
>
> Object-like and function-like macro is mentioned in 16.3p2,3.[/color]
Gotcha. I never used those terms before and they'd slipped off my mind,
obviously.
V
--
Please remove capital As from my address when replying by mail
|

March 14th, 2006, 03:45 PM
|
|
|
Re: object-like macro used like function-like macro
>>>I am fairly perplexed as to your statement about not finding this "case[color=blue][color=green][color=darkred]
>>>in
>>>the standard".[/color]
>>
>>
>> Sorry to be unprecise. What I do not find is, how a macro expansion is
>> carried out. And even if my problem was a rather stupid one (see other
>> post), I do not find the necessary paragraphs for the expansion rules.[/color]
>
> 16.3/8 and 16.3/9. I am surprised you didn't find it, considering that
> you read 16.3 apparently quite carefully.
>[/color]
Yes, me too. The reason is quite easy. I was a little bit irritated by the
wording:
-macro expansion (16p4)
-macro replacement (16.3, 16.3.8, 16.3.9,..)
-macro redefinition (16.3.2, 16.3.3)
In fact it is intuitive :).
Regards,
Patrick
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|
What is Bytes?
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over network members.
|