I want to convert string constant to preprocessing token using macro. Example:
// get the first character of marco argument to postfix of new data type. #define TYPE(typename) Prefix ## typename #typename[0] void main() { TYPE(int) a, b, c; // Prefixinti a, b, c; TYPE(float) x, y, z; // Prefixfloatf x, y, z; a = 3; }
is it possible in C/C++?
p/s: sorry for my poor English.
edited
#define TYPE(first_letter, rest) Prefix ## first_letter ## rest ## first_letter
typedef int TYPE(i,nt);
typedef float TYPE(f,loat);
int main(void)
{
TYPE(i,nt) a, b, c; // Prefixinti a, b, c;
TYPE(f,loat) x, y, z; // Prefixfloatf x, y, z;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With