Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #18933

Re: how warp a name by spaces in preprocessor mode

From James Kuyper <jameskuyper@verizon.net>
Newsgroups comp.lang.c
Subject Re: how warp a name by spaces in preprocessor mode
Date 2012-03-21 13:47 -0400
Organization A noiseless patient Spider
Message-ID <4F6A1424.9000301@verizon.net> (permalink)
References <43700cd3-9855-49b3-b0e2-342e18db13e9@fk28g2000vbb.googlegroups.com> <9sucluFp4oU1@mid.uni-berlin.de> <73d90e7f-f08b-42cf-8385-1df85c225e9e@r27g2000vbn.googlegroups.com>

Show all headers | View raw


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.

Back to comp.lang.c | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

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

csiph-web