how to surround a constant with quotes?

R

.rhavin grobert

lets say i do a

#define foo AbCdEf

now i want to do *something* that is NOT

#define foo2 "AbCdEf"

but has the same effect, ... so how can i tell the preprocessor "do me
some quotes around my foo-constant"?

-.rhavin;)
 
R

Richard Heathfield

..rhavin grobert said:
lets say i do a

#define foo AbCdEf

now i want to do *something* that is NOT

#define foo2 "AbCdEf"

but has the same effect, ... so how can i tell the preprocessor "do me
some quotes around my foo-constant"?

I'm not exactly sure which of the FAQs you're asking, but whichever one
it is, it's answered in Section 10 of the FAQ.
 
B

bytebro

lets say i do a

#define foo AbCdEf

now i want to do *something* that is NOT

#define foo2 "AbCdEf"

but has the same effect, ... so how can i tell the preprocessor "do me
some quotes around my foo-constant"?

-.rhavin;)

#define foo(x) #x
..
..
printf (foo(Put me some quotes around this\n));
..
 
S

santosh

..rhavin grobert said:
lets say i do a

#define foo AbCdEf

now i want to do *something* that is NOT

#define foo2 "AbCdEf"

but has the same effect, ... so how can i tell the preprocessor "do me
some quotes around my foo-constant"?

Yes.

#define foo(x) #x

What's wrong with the above solution for what you're trying to do?
 
P

pete

..rhavin grobert said:
lets say i do a

#define foo AbCdEf

now i want to do *something* that is NOT

#define foo2 "AbCdEf"

but has the same effect, ... so how can i tell the preprocessor "do me
some quotes around my foo-constant"?

/* BEGIN new.c */

#include <stdio.h>

#define foo AbCdEf
#define str(x) # x
#define xstr(x) str(x)

int main(void)
{
puts(xstr(foo));
return 0;
}

/* END new.c */
 
O

Old Wolf

#define foo(x) #x

What's wrong with the above solution for what you're trying to do?

Well, he would need to do it in several stages:
#define BAR(x) #x
#define BAZ(x) BAR(x)
#define foo2 BAZ(foo)
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top