473,385 Members | 1,973 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Preprocessor brain drain

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?

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Nov 14 '05 #1
3 1408
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;
}

--
Für Google, Tux und GPL!
Nov 14 '05 #2
Christopher Benson-Manica wrote:

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

--
Er*********@sun.com
Nov 14 '05 #3


Christopher Benson-Manica wrote:
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?


Hope this helps:

http://www.eskimo.com/~scs/C-faq/q11.17.html

Ed.

Nov 14 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: shea martin | last post by:
Is there a way to keep track of a build number within a program? Essentially incrementing a #define everytime the program is compiled (at link time would be even better, though tougher to...
205
by: Jeremy Siek | last post by:
CALL FOR PAPERS/PARTICIPATION C++, Boost, and the Future of C++ Libraries Workshop at OOPSLA October 24-28, 2004 Vancouver, British Columbia, Canada http://tinyurl.com/4n5pf Submissions
24
by: Nudge | last post by:
I have an array, and an unrolled loop which looks like this: do_something(A); do_something(A); .... do_something(A); I thought: why should I type so much? I should write a macro. So I was...
16
by: Trying_Harder | last post by:
Is it possible to redefine a macro with global scope after undefining it in a function? If yes, could someone explain how? /If/ my question above isn't very clear you can refer to the...
13
by: Chris Croughton | last post by:
Is the following code standard-compliant, and if so what should it do? And where in the standard defines the behaviour? #include <stdio.h> #define DEF defined XXX int main(void) { int...
9
by: Walter Roberson | last post by:
I have run into a peculiarity with SGI's C compiler (7.3.1.2m). I have been reading carefully over the ANSI X3.159-1989 specification, but I cannot seem to find a justification for the behaviour....
7
by: Erik Leunissen | last post by:
L.S. How can I make certain code parts be compiled conditionally, depending on the definition of a macro such as: #define VERSION "2.3" Is it all right to do things like:
32
by: spibou | last post by:
Is the output of the C preprocessor deterministic ? What I mean by that is , given 2 compilers which conform to the same standard, will their preprocessors produce identical output given as input...
25
by: Gernot Frisch | last post by:
Hi, I want to build a encryption macro set, that can crypt: char secret = CRYPT("KungFu"); to anything unreadable, and then have a function: char* DECRYPT(char* str) { ...
31
by: Sam of California | last post by:
Is it accurate to say that "the preprocessor is just a pass in the parsing of the source file"? I responded to that comment by saying that the preprocessor is not just a pass. It processes...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.