This started as a joke type of Cython, with me making a lot of silly defines to emulate python using C. Then I realized it was actually sort of convenient for debugging and quickly hacking together programs.
I have a define that mostly works, using sizeof
to distinguish types, but a 3 or 7 character char array/string + \0
will be printed as a double or an int. Is there anyway around this? I was considering using a try-exception to subscript it to see if it's a string, but I can't implement it.
#include <stdio.h>
#define print(n) if(sizeof(n)==8) printf("%f\n",n); \
else if(sizeof(n)==4) printf("%i\n",n); \
else printf("%s\n",n);
int main()
{
print("Hello world!") // these all work perfectly
print(8.93)
print(4)
print("abc") // these are interpreted as ints or doubles
print("1234567")
return 0;
}