putting quotes around macro

R

rparimi

Hi,

I have a macro whose value is obtained from a combination of other
macros. E.g

#define ALL_TESTS \
INIT_TEST ("string one", 1) \
DEF_TEST("string two", 2)

Upon execution, the value of ALL_TESTS gets evaluated to something in
this format:

{"string one", 1, NULL}, {"string two", 2, NULL}

I want to cast the above into a string so that I can parse the string
and extract fields of interest. I tried #ALL_TESTS but this doesn't
seem to work.. Is there a way to get this working?

Thanks
 
M

Mohan

Hi,

I have a macro whose value is obtained from a combination of other
macros. E.g

#define ALL_TESTS \
INIT_TEST ("string one", 1) \
DEF_TEST("string two", 2)
How are INIT_TEST and DEF_TEST defined?
Upon execution, the value of ALL_TESTS gets evaluated to something in
this format:

{"string one", 1, NULL}, {"string two", 2, NULL}

I want to cast the above into a string so that I can parse the string
and extract fields of interest. I tried #ALL_TESTS but this doesn't
seem to work.. Is there a way to get this working?

Please provide smallest possible code to demonstrate your question. It
helps more clear understanding of your problem (or requirement).

Mohan
 
T

Thad Smith

Hi,

I have a macro whose value is obtained from a combination of other
macros. E.g

#define ALL_TESTS \
INIT_TEST ("string one", 1) \
DEF_TEST("string two", 2)

Upon execution, the value of ALL_TESTS gets evaluated to something in
this format:

{"string one", 1, NULL}, {"string two", 2, NULL}

I want to cast the above into a string so that I can parse the string
and extract fields of interest. I tried #ALL_TESTS but this doesn't
seem to work.. Is there a way to get this working?

Not tested, but probably good:

#define STRINGIZE(s) STRINGIZE2(s)
#define STRINGIZE2(s) #s

#include <stdio.h>
....
printf("%s", STRINGIZE(ALL_TESTS));
 

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,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top