stringification Questions
13
Solved
As mentioned in many of my previous questions, I'm working through K&R, and am currently into the preprocessor. One of the more interesting things — something I never knew before from any...
Mendy asked 19/10, 2008 at 19:51
3
Solved
Can I enumerate char* members of a class (or struct) in C++? If so can I print the variables names as strings? Using pre-processor?
I have a class with all const char* members. It would be good if...
Missie asked 21/3, 2013 at 14:28
4
Solved
Consider this:
#define STRINGIFY(A) #A
If I then later write:
STRINGIFY(hello)
Is the compiler actually seeing this:
#hello
I think it is that additional hash in front of #A that ...
Sociopath asked 23/12, 2012 at 13:55
5
Solved
I wish there was a way to split a #include directive across two lines, so that my code can conform to 80 characters per line, despite the necessity of a very long include path.
Other than expandin...
Conjugate asked 4/10, 2012 at 19:3
1
Solved
I have a constant defined:
#define MAX_STR_LEN 100
I am trying to do this:
scanf("%" MAX_STR_LEN "s", p_buf);
But of course that doesn't work.
What preprocessor trick can be use to convert t...
Caril asked 29/9, 2012 at 0:51
2
Solved
I want to know the reason behind the output of this code. I couldn't come up with an answer.
#define f(a,b) a##b
#define g(a) #a
#define h(a) g(a)
void main()
{
printf("%s %s",h(f(1,2)),g(f(1,2))...
Doubly asked 23/7, 2012 at 9:48
1
Solved
I have a common string macro that I want to convert to a length-value string, all within macros, if possible, so everything ends up in .rodata.
#define PAYLOAD "xyz"
#define PAYLOAD_LEN (sizeof(PA...
Chaudfroid asked 27/6, 2012 at 19:29
4
Solved
Is there some way to embed pragma statement in macro with other statements?
I am trying to achieve something like:
#define DEFINE_DELETE_OBJECT(type) \
void delete_ ## type_(int handle); \
void...
Canady asked 12/6, 2010 at 21:9
4
I have many variables that are named the same as elements in an engineering specification document so the string version of the name is also useful.
I find myself using a macro like this a lot:
#...
Mainis asked 21/12, 2011 at 23:13
3
Is there an easy way to add regex modifiers such as 'i' to a quoted regular expression? For example:
$pat = qr/F(o+)B(a+)r/;
$newpat = $pat . 'i'; # This doesn't work
The only way I can think of...
Snag asked 10/11, 2011 at 16:15
2
Solved
I would like to evaluate a token before it is concatenated with something else. The "problem" is that the standard specifies the behaviour as
before the replacement list is reexamined for more m...
Katherinkatherina asked 17/10, 2011 at 14:49
2
Solved
I am defining a macro that evaluates to a constant string, holding the filename and the line number, for logging purposes.
It works fine, but I just can't figure out why 2 additional macros are ne...
Cort asked 12/9, 2011 at 12:15
1
Solved
#define JNI_DECLARE( classname, methodname ) \
classname ## methodname( JNI* env )
#define JAVA_CLASS Java_com_example
void JNI_DECLARE( JAVA_CLASS, open ) {}
This expands to:
void JAVA_CLASS...
Mcripley asked 12/8, 2011 at 19:29
2
Solved
GNU's cpp allows you to turn macro parameters into strings like so
#define STR(x) #x
Then, STR(hi) is substituted with "hi"
But how do you turn a macro (not a macro parameter) into a string?
S...
Tedmund asked 28/7, 2011 at 0:37
4
Solved
Note: This question has nothing to do with OpenCL per se... check the last paragraph for a succinct statement of my question. But to provide some background:
I'm writing some C++ code that makes u...
Jackjackadandy asked 28/6, 2011 at 5:54
2
Solved
I want to stringify the result of a macro expansion.
I've tried with the following:
#define QUOTE(str) #str
#define TEST thisisatest
#define TESTE QUOTE(TEST)
And TESTE gets expanded to: "TEST"...
Fidget asked 5/8, 2010 at 21:30
3
Solved
My guess is the answer to this question is no, but it would be awesome if there was a way. To clarify, assume I have the following macro:
#define MY_VARIADIC_MACRO(X...) // Does some stuff here in...
Yetty asked 10/5, 2011 at 23:37
3
Solved
I'm trying to figure out how I can concatenate a #define'd int to a #define'd string using the C Preprocessor. My compiler is GCC 4.1 on CentOS 5. The solution should also work for MinGW.
I'd like...
Florafloral asked 28/3, 2011 at 13:44
7
I came across this example of an assertion and was wondering what the # is for:
#define ASSERT( x ) if ( !( x ) ) { \
int *p = NULL; \
DBGPRINTF("Assert failed: [%s]\r\n Halting.", #x); \
*p=1;...
Distinct asked 18/3, 2011 at 15:58
2
Solved
Disclaimer: I am not a C programmer.
I have recently seen a friend's project. Due to reasons I don't understand, he writes code in a string which is compiled at runtime. This results in something ...
Apennines asked 26/11, 2010 at 10:23
3
Solved
After reading about VA_NARG
I tried to implement function overloading depending on number of arguments in C using macros.
Now the problem is:
void hello1(char *s) { ... }
void hello2(char *s, cha...
Nuptial asked 22/9, 2010 at 12:53
2
Solved
Why do these blocks of code yield different results?
Some common code:
#define PART1PART2 works
#define STRINGAFY0(s) #s
#define STRINGAFY1(s) STRINGAFY0(s)
case 1:
#define GLUE(a,b,c) a##b##c...
Hyohyoid asked 19/7, 2010 at 7:2
2
Solved
If I add a macro "FOO=bar" under GCC_PREPROCESSOR_DEFINITIONS (or Preprocessor Macros if you use XCode"), what would be the best way to access the value of "FOO"?
Currently, I use the clumsy:
#d...
Mohair asked 16/7, 2010 at 3:36
3
Solved
I have some fairly generic code which uses preprocessor macros to add a certain prefix onto other macros. This is a much simplified example of what happens:
#define MY_VAR(x) prefix_##x
"prefix_...
Iliac asked 24/4, 2010 at 6:47
2
Solved
At least some C preprocessors let you stringize the value of a macro, rather than its name, by passing it through one function-like macro to another that stringizes it:
#define STR1(x) #x
#define ...
Weizmann asked 1/5, 2010 at 23:17
© 2022 - 2024 — McMap. All rights reserved.