473,396 Members | 1,942 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 1629
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

25
by: Sabyasachi Basu | last post by:
While trying to port some stuff from Unix to Windows, I encountered a strange behaviour of function macros with empty arguments. Here is a small snippet which illustrates the problem: #include...
37
by: seberino | last post by:
I've been reading the beloved Paul Graham's "Hackers and Painters". He claims he developed a web app at light speed using Lisp and lots of macros. It got me curious if Lisp is inherently faster...
37
by: hasadh | last post by:
Hello, probably this may be a simple qn to u all but I need an answer plz. In my software i used macros like OK,TRUE,FALSE,FAILURE . A friend who included this code as a library into his module...
1
by: rir3760 | last post by:
Since a few days ago I have been working with the program I post below (a school assignment). The purpose of the program is to work with the va_ macros (stdarg.h) and arrays of arrays, hopefully...
6
by: DBxGlock | last post by:
I'm trying to create the equivalent of a post build event for a website. I have the "Web Deployment Projects" add-in installed and am attempting to follow the instructions in the "Using Web...
3
by: Michael Brennan | last post by:
Hi, does the standard say if the isalpha, isdigit, etc. functions in ctype.h are functions or macros? My old pre-ansi book says they are macros, but I've seen man pages that say they are...
33
by: Robert Seacord | last post by:
When writing C99 code is a reasonable recommendation to use inline functions instead of macros? What sort of things is it still reasonable to do using macros? For example, is it reasonable to...
20
by: copx | last post by:
Is it true that C macros are unsafe when combined with side effects even if they are "clean" e.g. could foo_macro(++c); execute "++c" multiple times even if foo_macro is "clean"? I have always...
7
by: vippstar | last post by:
This question might be OT I apologise if it is. All functions are allowed to be macros. In a hypothetical implementation a tolower might be written as: #define tolower(x) \ (x) == 'A' ? 'a' :...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.