Connecting Tech Pros Worldwide Help | Site Map

macros standard equivalent?

 
LinkBack Thread Tools Search this Thread
  #1  
Old November 15th, 2006, 04:25 PM
aaragon
Guest
 
Posts: n/a
Default macros standard equivalent?

Hello All,

I am using the following macros;

#define str(x) # x
#define conc(x,y) x ## y

to play with strings. Does anyone know if there is an equivalent
provided by the standard library to accomplish this? Thank you,

aa


  #2  
Old November 15th, 2006, 04:35 PM
Victor Bazarov
Guest
 
Posts: n/a
Default Re: macros standard equivalent?

aaragon wrote:
Quote:
Hello All,
>
I am using the following macros;
>
#define str(x) # x
#define conc(x,y) x ## y
>
to play with strings. Does anyone know if there is an equivalent
provided by the standard library to accomplish this? Thank you,
No, there isn't anything. However, to properly concatenate those
you might want to use indirection, i.e. have another set of the two
macros to help:

#define applystringize(x) # x
#define str(x) applystringize(x)
#define applyconcatenate(x,y) x ## y
#define conc(x,y) applyconcatenate(x,y)

because otherwise if you use macros like 'conc(x, str(x))', it
won't do it without this extra indirection stuff.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask


  #3  
Old November 15th, 2006, 05:35 PM
Phlip
Guest
 
Posts: n/a
Default Re: macros standard equivalent?

aaragon wrote:
Quote:
I am using the following macros;
>
#define str(x) # x
#define conc(x,y) x ## y
>
to play with strings. Does anyone know if there is an equivalent
provided by the standard library to accomplish this? Thank you,
Those are "stringerization" and "token pasting". They are one of a few
reasons to use macros, and nothing below the macro layer, in the layer of
C++ keywords, can do anything like them. They change the text that the see.
So

conc(in,t) x = 42;

gets compiled as

int x = 42;

Nothing in the standard library can ever do that!

(May we ask what you use those macros for? Situations that actually need
them are kind'a rare...)

--
Phlip
http://www.greencheese.us/ZeekLand <-- NOT a blog!!!


 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,840 network members.