Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #18929 > unrolled thread
| Started by | Arek <oczykota@gmail.com> |
|---|---|
| First post | 2012-03-21 08:20 -0700 |
| Last post | 2012-03-21 13:47 -0400 |
| Articles | 4 — 3 participants |
Back to article view | Back to comp.lang.c
how warp a name by spaces in preprocessor mode Arek <oczykota@gmail.com> - 2012-03-21 08:20 -0700
Re: how warp a name by spaces in preprocessor mode jt@toerring.de (Jens Thoms Toerring) - 2012-03-21 16:07 +0000
Re: how warp a name by spaces in preprocessor mode Arek <oczykota@gmail.com> - 2012-03-21 09:41 -0700
Re: how warp a name by spaces in preprocessor mode James Kuyper <jameskuyper@verizon.net> - 2012-03-21 13:47 -0400
| From | Arek <oczykota@gmail.com> |
|---|---|
| Date | 2012-03-21 08:20 -0700 |
| Subject | how warp a name by spaces in preprocessor mode |
| Message-ID | <43700cd3-9855-49b3-b0e2-342e18db13e9@fk28g2000vbb.googlegroups.com> |
Hi, How can I warp a name by space using preprocessor? for example: How write macro: GET_LAST_ELEMENT(A B C D) that it return D
[toc] | [next] | [standalone]
| From | jt@toerring.de (Jens Thoms Toerring) |
|---|---|
| Date | 2012-03-21 16:07 +0000 |
| Message-ID | <9sucluFp4oU1@mid.uni-berlin.de> |
| In reply to | #18929 |
Arek <oczykota@gmail.com> wrote:
> How can I warp a name by space using preprocessor?
> for example:
> How write macro:
> GET_LAST_ELEMENT(A B C D)
The arghuments of a macro must be separated by commas, so this
one won't work. And what's the "name" here?
> that it return
A macro doesn't return anything, it's not a function but does
just textual replacement.
> D
You can have macro like
#define GET_LAST)F_FOUR( A, B, C, D ) D
and when called e.g. as
int x = GET_LAST_OF_FOUR( 1, 2, 3, 4 );
this will be replaced by
int x = 4;
But I have a feeling that this isn't what you had in mind...
If you're looking for a macro that takes apart a string,
e.g. something that, when given an argument of "A B C D",
will replace it by "D" (the part of the string after the
last space) then you're rather likely out of luck, better
write a function.
Regards, Jens
--
\ Jens Thoms Toerring ___ jt@toerring.de
\__________________________ http://toerring.de
[toc] | [prev] | [next] | [standalone]
| From | Arek <oczykota@gmail.com> |
|---|---|
| Date | 2012-03-21 09:41 -0700 |
| Message-ID | <73d90e7f-f08b-42cf-8385-1df85c225e9e@r27g2000vbn.googlegroups.com> |
| In reply to | #18931 |
On 21 Mar, 17:07 (Jens Thoms Toerring) wrote: > If you're looking for a macro that takes apart a string, > e.g. something that, when given an argument of "A B C D", > will replace it by "D" (the part of the string after the > last space) then you're rather likely out of luck, better > write a function. yes. something like that. if i make: #define w _a _b _c then w will be replaced by "_a _b _c" I want to have macro GET_LAST_ELEMENT(w) which will be replaced by _c
[toc] | [prev] | [next] | [standalone]
| From | James Kuyper <jameskuyper@verizon.net> |
|---|---|
| Date | 2012-03-21 13:47 -0400 |
| Message-ID | <4F6A1424.9000301@verizon.net> |
| In reply to | #18932 |
On 03/21/2012 12:41 PM, Arek wrote: > On 21 Mar, 17:07 (Jens Thoms Toerring) wrote: > >> If you're looking for a macro that takes apart a string, >> e.g. something that, when given an argument of "A B C D", >> will replace it by "D" (the part of the string after the >> last space) then you're rather likely out of luck, better >> write a function. > > yes. something like that. > if i make: > #define w _a _b _c > then w will be replaced by "_a _b _c" > I want to have macro > GET_LAST_ELEMENT(w) > which will be replaced by _c As he said, you're out of luck - C's preprocessing capabilities are quite limited, they're not powerful enough to do that. Possibly you're taking the wrong approach to this; possibly C isn't the right language for what you want to do. You might need to use some other preprocessor such as m4, or you might need to write your own preprocessor program to automatically generate the C code that you want GET_LAST_ELEMENT() to generate. If you could give some context, we might be able to suggest an alternative approach. You can't #define GET_LAST_ELEMENT() to work the way you want it to, but could you provide some example code that shows us what you would want to do with it, if it could be #defined? The code should be "real" enough to make it clear to us, not only about what you want GET_LAST_ELEMENT() to do, but more importantly, why you want it to do that.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.c
csiph-web