Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert string to non string with C macro [duplicate]

I know that it is possible to convert something to string with macro like this:

#define STRING(s) #s

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

But it is possible to do the opposite?

#define MyType(type) ??? 

MyType("uint16_t") myint = 100;
like image 731
y30 Avatar asked Dec 22 '16 11:12

y30


1 Answers

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

But you might use some different preprocessor or some script to transform your weird source file into some C file.

You could also perhaps customize your compiler (e.g. with a GCC plugin or a MELT extension) to add such behavior thru additional builtins or pragmas. That would be very compiler specific, and probably requires more work than what you can afford.

like image 168
Basile Starynkevitch Avatar answered Oct 01 '22 03:10

Basile Starynkevitch