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
|