Connecting Tech Pros Worldwide Forums | Help | Site Map

object-like macro used like function-like macro

Patrick Kowalzick
Guest
 
Posts: n/a
#1: Mar 14 '06
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



Victor Bazarov
Guest
 
Posts: n/a
#2: Mar 14 '06

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
Patrick Kowalzick
Guest
 
Posts: n/a
#3: Mar 14 '06

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


Patrick Kowalzick
Guest
 
Posts: n/a
#4: Mar 14 '06

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]


Victor Bazarov
Guest
 
Posts: n/a
#5: Mar 14 '06

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
Patrick Kowalzick
Guest
 
Posts: n/a
#6: Mar 14 '06

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


Closed Thread