469,945 Members | 1,809 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,945 developers. It's quick & easy.

Token pasting (## operator) - Add whitespace to a token

Hi,

token pasting means, that normally whitespaces and comments are deleted
before and after the ## operator. I want the preprocessor to hold an
existing whitespace while replacing the argument of a macro. Example:

The following define and macro

#define ISR_CAT1(NAME) __interrupt void ##NAME(void)

ISR_CAT1(myIsrHandler)
{

}

should be expanded to

__interrupt void myIsrHandler(void)
{

}

But the preprocessor does the following replacement (deleting
whitespaces before ##):

__interrupt voidmyIsrHandler(void)
{

}

Is there any possibility to avoid this kind of replacement/deleting the
whitespaces in front of ## operator?

Nov 15 '05 #1
3 3002

Wessi wrote:
Hi,

token pasting means, that normally whitespaces and comments are deleted
before and after the ## operator. I want the preprocessor to hold an
existing whitespace while replacing the argument of a macro. Example:

The following define and macro

#define ISR_CAT1(NAME) __interrupt void ##NAME(void)

ISR_CAT1(myIsrHandler)
{

}

should be expanded to

__interrupt void myIsrHandler(void)
{

}

But the preprocessor does the following replacement (deleting
whitespaces before ##):

__interrupt voidmyIsrHandler(void)
{

}

Is there any possibility to avoid this kind of replacement/deleting the
whitespaces in front of ## operator?


Why are you using "##" ? Following definition should work.
#define ISR_CAT1(NAME) __interrupt void NAME(void)

Nov 15 '05 #2
On Thu, 11 Aug 2005 04:40:12 -0700, Wessi wrote:
Hi,

token pasting means, that normally whitespaces and comments are deleted
before and after the ## operator. I want the preprocessor to hold an
existing whitespace while replacing the argument of a macro. Example:
The result of token pasing must be a valid pp-token and only pp-tokens
like character constants and string literals can contain spaces. Trying to
create another type of pp-token containing spaces doesn't make any sense.
The following define and macro

#define ISR_CAT1(NAME) __interrupt void ##NAME(void)

ISR_CAT1(myIsrHandler)
{

}

should be expanded to

__interrupt void myIsrHandler(void)
{

}
Token pasting is used to create new (composite) tokens but there aren't
any such tokens in your desired expansion; your error is in trying to use
token pasting when it is not appropriate. Use simply:

#define ISR_CAT1(NAME) __interrupt void NAME(void)
But the preprocessor does the following replacement (deleting
whitespaces before ##):

__interrupt voidmyIsrHandler(void)
{

}
Yes, your macro tries to paste the tokens void and myIsrHandler into a
single one whereas what you really need is just to leave them as separate
tokens.
Is there any possibility to avoid this kind of replacement/deleting the
whitespaces in front of ## operator?


Don't use token pasting.

Lawrence
Nov 15 '05 #3
Thanks, you're right. I had another problem with double macro
expansion, which made me believe, that your solution will not work.

Nov 15 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Jean-Claude Gervais | last post: by
4 posts views Thread by Nelson Hsu | last post: by
8 posts views Thread by Mark Odell | last post: by
7 posts views Thread by Mark Odell | last post: by
13 posts views Thread by Henry Townsend | last post: by
2 posts views Thread by mark.bergman | last post: by
3 posts views Thread by Rudhir | last post: by
1 post views Thread by jeff | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.