469,623 Members | 997 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,623 developers. It's quick & easy.

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

Nov 15 '06 #1
2 1438
aaragon wrote:
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
Nov 15 '06 #2
aaragon wrote:
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!!!
Nov 15 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

25 posts views Thread by Sabyasachi Basu | last post: by
37 posts views Thread by hasadh | last post: by
1 post views Thread by rir3760 | last post: by
3 posts views Thread by Michael Brennan | last post: by
33 posts views Thread by Robert Seacord | last post: by
20 posts views Thread by copx | last post: by
7 posts views Thread by vippstar | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.