I have a variable that I do not type of. So to print that I do not know whether to use %d
or %f
. For this I want to check its type before printing.
Now to check its type I want to use like this:
if (typeof(int) == voltage) {
snprintf(chars, sizeof(chars), "%d", voltage);
}
Now this is not valid.
I need a way to check the variable type.
I am testing with two variables, but I think following is not valid either.
And how to use this getIntType function/(What is it called? macro?) that I got and modified from here and here?
#define getIntType(a,b) ({ __auto_type _a = (a); __auto_type _b = (b); _a == typeof(int) ? _a : _b; });
int a = 10;
double b = 20.0;
int x = getIntType(a,b)==?; //How to call and how to store in type var of this x?
and how to return value from macro/ how to use this?
#define typecheck(type,x) \
({ type __dummy; \
typeof(x) __dummy2; \
(bool)(&__dummy == &__dummy2); \
}) // How to return value to check?
//Then how to check?
int a = 10;
double b = 20.0;
//int x = getIntType(a,b)? a : b;
//bool isInt = typecheck(typeof(int), a);