Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

PSoC™ 5, 3 & 1 Forum Discussions

Not applicable



I need to stringify a macro expansion, as with gnu c preprocessor by prepending it with '#', but this dont work and give the error "illegal character `#' ".


The macro is define in makefile as -DVERSION="$(git describe)"


and used as const char Version[] = #VERSION ;


It seems that stringification is possible since there is a preprocessor error saying "Stringified macro arg is too long" in the documentation, but it may have an other syntax.


Please, is anyone have allready used stringification with Imagecraft compiler (PsocDesigner 5.4).





4 Replies
Level 8
Level 8
100 likes received 50 likes received 25 likes received

Just use VERSION - cpp expands all defines and macros when it encounters them, there is no need for a special prefix. The '#' merely tells cpp that now preprocessor directive follows.


I don't think that you can do runtime expansion of command output on Windows, though (on Linux you would do a backtick expression).

Not applicable

Thank, but I try with this code :
const char Version[]=VERSION;


the compiler give me the errors :


missing { in initialization of `incomplete array of const char'


undeclared identifier `test01'


initializer must be constant


I want the expantion to have double cote :


const char Version[]="test01";


This is what I get with the # preprocessor operator with gnu cpp. It is called 'stringification operator'.


The runtime expantion work as wanted because it is interpreted by gnu make. I just put the macro define in the project setting:


VERSION="$(shell c:\cygwin\bin\git describe)"


My current git tag is test01, so VERSION expand to it.

Not applicable

Ok, I've found the solution.


Stringify operator is working, but only in macro define, and is done before expantion of the arcgument. So, defining a macro for stringification is not sufficient. when writing :


#define STR(x) #x


const char Version[]=STR(VERSION);


the expantion give :


const char Version[]="VERSION";


I have to write a second no-op macro to let the preprocessor first expand VERSION to test01, then stringify test01 to "test01":


#define STR(x)    #x
#define STRX(x)    STR(x)
const char Version[]=STRX(VERSION);


This time preprocessor expant to :


const char Version[]="test01"


Glad you got it working. And I learned something new today 🙂