Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > how to surround a constant with quotes?

Reply
Thread Tools

how to surround a constant with quotes?

 
 
.rhavin grobert
Guest
Posts: n/a
 
      03-13-2007
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

 
Reply With Quote
 
 
 
 
Richard Heathfield
Guest
Posts: n/a
 
      03-13-2007
..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.
 
Reply With Quote
 
 
 
 
bytebro
Guest
Posts: n/a
 
      03-13-2007
On 13 Mar, 13:57, ".rhavin grobert" <c...@yahoo.de> 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"?
>
> -.rhavin


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



 
Reply With Quote
 
santosh
Guest
Posts: n/a
 
      03-13-2007

..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?

 
Reply With Quote
 
pete
Guest
Posts: n/a
 
      03-13-2007
..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
 
Reply With Quote
 
Old Wolf
Guest
Posts: n/a
 
      03-13-2007
On Mar 14, 3:59 am, "santosh" <santosh....@gmail.com> wrote:
> .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)

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
pointers to constant characters and constant pointers to characters sam_cit@yahoo.co.in C Programming 4 12-14-2006 11:10 PM
len(var) is [CONSTANT] equal to len(var) == [CONSTANT]? Tor Erik Soenvisen Python 14 11-23-2006 09:57 PM
"Non-constant" constant can't be used as template argument Martin Magnusson C++ 2 10-08-2004 08:41 AM
Understanding How To Use #ifdef Constant #define Constant Sequence In Multible Files Christopher M. Lusardi C++ 1 09-02-2004 07:43 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57