object-like macro used like function-like macro

P

Patrick Kowalzick

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
 
V

Victor Bazarov

Patrick said:
Is this valid? I do not find the case in the standard:

void foo( int ) {}

#define FOO foo

int main()
{
FOO(0);
return 0;
}

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
 
P

Patrick Kowalzick

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;
}

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
 
P

Patrick Kowalzick

Hello Victor,
I am fairly perplexed as to your statement about not finding this "case in
the standard".

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.
Where in the Standard did you look?

Chapter 16.
And what is "object-like macro" you're referring to in your subject line?

Object-like and function-like macro is mentioned in 16.3p2,3.

Thanks,
Patrick
 
V

Victor Bazarov

Patrick said:
Hello Victor,




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.

16.3/8 and 16.3/9. I am surprised you didn't find it, considering that
you read 16.3 apparently quite carefully.
Chapter 16.

Yep, it's there alright.
Object-like and function-like macro is mentioned in 16.3p2,3.

Gotcha. I never used those terms before and they'd slipped off my mind,
obviously.

V
 
P

Patrick Kowalzick

I am fairly perplexed as to your statement about not finding this "case
16.3/8 and 16.3/9. I am surprised you didn't find it, considering that
you read 16.3 apparently quite carefully.

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top