Google Mail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Macro preprocessing
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Follow-up To:
Add Cc | Add Follow-up to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers that you hear
 
dhun  
View profile   Translate to Translated (View Original)
 More options 7 Nov, 17:59
Newsgroups: comp.lang.c
From: dhun <mdhua...@gmail.com>
Date: Sat, 7 Nov 2009 09:59:24 -0800 (PST)
Local: Sat 7 Nov 2009 17:59
Subject: Macro preprocessing
Hi All,
I have a following kind of situation.

#define i(p) p
#define r(x) i(in)##_##x

int main(){
#define in a
int a,a_b;
a = r(b);
#undef in

}

where I need to construct a symbol ab, at the place where code is
executed.

A g++ -E test.c, however insert a space between a and b.

What could be possible solution for this?


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Andrey Vul  
View profile   Translate to Translated (View Original)
 More options 7 Nov, 21:26
Newsgroups: comp.lang.c
From: Andrey Vul <andrey....@gmail.com>
Date: Sat, 7 Nov 2009 13:26:55 -0800 (PST)
Local: Sat 7 Nov 2009 21:26
Subject: Re: Macro preprocessing
On Nov 7, 12:59 pm, dhun <mdhua...@gmail.com> wrote:

Premature ## . Create helper macros to redirect the preprocessor until
only the expanded token is pasted.
In this case:
#define s__(x,y) x##y
#define s(x,y) s__(x,y)
#define r(x) s(i(in),s(_,x))

Two things happen here:
1. r is defined as the result of a redirected paste macro.
2. s creates redirection so that results of expansion instead of the
raw tokens are pasted.

The paste operator (##) has a higher precedence than expansion. so you
need to create a paster and a wrapper to allow for expansion before
pasting.
With my modifications, gcc does not warn about invalid tokens.
This warning needs to be taken very seriously though, it shows that
your code is missing something.


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google