Preprocessor brain drain

  • Thread starter Christopher Benson-Manica
  • Start date
C

Christopher Benson-Manica

If I have a symbol defined at preprocessing (assume it's all digits),
how can I make that symbol into a string constant for compiling?
 
A

Alexander Bartolich

begin followup to Christopher Benson-Manica:
If I have a symbol defined at preprocessing (assume it's all digits),
how can I make that symbol into a string constant for compiling?

int main()
{
#define MAGIC 31337
#define QUOTE_SYM(s) #s
#define QUOTE_NUM(s) QUOTE_SYM(s)
puts(QUOTE_SYM(MAGIC));
puts(QUOTE_NUM(MAGIC));
return 0;
}
 
E

Eric Sosman

Christopher said:
If I have a symbol defined at preprocessing (assume it's all digits),
how can I make that symbol into a string constant for compiling?

#define STRINGIZE(x) STRINGIZE_HELPER(x)
#define STRINGIZE_HELPER(x) #x

#define SYMBOL all digits
puts (STRINGIZE(SYMBOL));
 

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,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top