Converting a macro to a string

T

Thierry Lam

Let's say I have the following codes:

#define macHOME $HELLOHOME

How can I concatenate the above macro into a string, for example I want
the following result:

char *path = "$HELLOHOME/test";

I can achieve the above be defining the macro as "$HELLOHOME", but is
there any other ways to do it?

Thanks
Thierry
 
V

Victor Bazarov

Thierry said:
Let's say I have the following codes:

#define macHOME $HELLOHOME

How can I concatenate the above macro into a string, for example I want
the following result:

char *path = "$HELLOHOME/test";

I can achieve the above be defining the macro as "$HELLOHOME", but is
there any other ways to do it?

See preprocessor operator # (stringize) and ## (token catenation).

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,779
Messages
2,569,606
Members
45,239
Latest member
Alex Young

Latest Threads

Top