By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,405 Members | 1,053 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,405 IT Pros & Developers. It's quick & easy.

Macro invocation

P: n/a
Ron
What kind of tokens can I pass as arguments? Can I pass more than one token
for a single argument? eg.

#define MYMACRO(arg1, arg2) arg1 arg2

MYMACRO("abc" L'd' .12, "def")

Is it valid? But if I can pass any pp-token I could even pass a comma since
it's an op-or-punc pp-token, ok? So i could write:

MYMACRO("abc" , L'd' .12, "def")

That is ambiguous since it's not clear if the first comma closes the first
argument or if it's just a token to pass. Please, give me an answer.

Greetings.

Jul 22 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"Ron" <no@spam.com> wrote...
What kind of tokens can I pass as arguments? Can I pass more than one token for a single argument? eg.

#define MYMACRO(arg1, arg2) arg1 arg2

MYMACRO("abc" L'd' .12, "def")

Is it valid?
Yes, since the comma is the only op-or-punc here, the first argument
is ["abc" L'd' .12] and the second is ["def"]. See 16.3/10.
But if I can pass any pp-token I could even pass a comma since
it's an op-or-punc pp-token, ok?
Not in the same level as the parentheses. The comma is a special token.
So i could write:

MYMACRO("abc" , L'd' .12, "def")

That is ambiguous since it's not clear if the first comma closes the first
argument or if it's just a token to pass. Please, give me an answer.


This is not ambiguous. Each comma at the same level as parentheses
separates macro arguments. In this case given the definition of MYMACRO
as stated in your post, the error is: too many macro arguments.

If you need to pass a comma, surround the corresponding argument with
parentheses:

MYMACRO(("abc" , L'd' .12), "def")

Victor
Jul 22 '05 #2

P: n/a
Ron
thanks!
Jul 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.