By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,134 Members | 1,942 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,134 IT Pros & Developers. It's quick & easy.

how to surround a constant with quotes?

P: n/a
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;)

Mar 13 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a
..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.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Mar 13 '07 #2

P: n/a
On 13 Mar, 13:57, ".rhavin grobert" <c...@yahoo.dewrote:
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));
..

Mar 13 '07 #3

P: n/a

..rhavin grobert wrote:
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?

Mar 13 '07 #4

P: n/a
..rhavin grobert wrote:
>
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 */

--
pete
Mar 13 '07 #5

P: n/a
On Mar 14, 3:59 am, "santosh" <santosh....@gmail.comwrote:
.rhavin grobert wrote:
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,

#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)

Mar 13 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.