Convert string to non string with C macro

I know that you can convert something to a macro line like this:

#define STRING(s) #s printf("%s", STRING(i am string)); 

But is it possible to do the opposite?

 #define MyType(type) ??? MyType("uint16_t") myint = 100; 
+5
source share
1 answer

AFAIK, this is not possible using the standard C preprocessor. What you want is not part of the standard language C11 (or C99). And not a single part of C ++ 11 or C ++ 14 (which is different from C).

But you can use some other preprocessor or some script to convert your strange source file to some C file.

You can also customize your compiler (for example, using the GCC or MELT plugin) to add this behavior through additional built-in functions or pragmas. This will be very specific to the compiler and will probably require more work than you can afford.

+4
source

Source: https://habr.com/ru/post/1261709/


All Articles