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


Groups > comp.lang.c > #18931

Re: how warp a name by spaces in preprocessor mode

From jt@toerring.de (Jens Thoms Toerring)
Newsgroups comp.lang.c
Subject Re: how warp a name by spaces in preprocessor mode
Date 2012-03-21 16:07 +0000
Organization Freie Universitaet Berlin
Message-ID <9sucluFp4oU1@mid.uni-berlin.de> (permalink)
References <43700cd3-9855-49b3-b0e2-342e18db13e9@fk28g2000vbb.googlegroups.com>

Show all headers | View raw


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

Back to comp.lang.c | Previous | Next — Previous in thread | Next 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