STRINGIFY in .cpp file

1.9k views Asked by At

I am reading some .cpp files made to compile them and have a mex file to use in MATLAB for a Level-2 S-Function.

I would like to know what is this instruction IN PRACTICE for:

#define STRINGIFY(x) #x
#define TOSTRING(x) STRINGIFY(x) 

Thanks for your help.

1

There are 1 answers

0
mastov On BEST ANSWER

For example, it can be useful in macros like asserts. In case the assert fails, you may not only want to know that something failed, but also what failed. Then you can create a string about the condition that actually didn't hold. Then you can use it to print an error message to the console or use it as description in an exception object.

EDIT: In case you were wondering more about why there are two macros doing the same thing, one just referring to the other, you can find the answer in the the question referred to by Piotr S. in the comments.