I am trying to use the stringizing operator #, but I get the error stray ‘#’ in program
. Here is how I am using it.
#define STR "SOME_STRING"
#define BM 8
#define NUM_OF_THREADS 8
#define VER_STR (STR #BM #NUM_THREADS)
I expect to get SOME_STRING88
for VER_STR
but instead get an error. What mistake am I doing?
You need to turn the numerical constants into a string. However,
#BM
is an error, since the syntax is only valid for macro parameters. So you need to force en expansion through an intermediate macro. And you may as well have a STRINGIFY macro to do it:You can see the above in action at http://ideone.com/cR1KZP
EDIT
As Magnus Hoff pointed out, you can invoke STRINGIFY directly as well: