I am using visual studio c++. I want to be able to switch between double and long long.
How can I use #ifdef in the following program? I want to use a more simpler solution to handle the case of multiple printf.
//#define TYPE_SWITCH
#ifdef TYPE_SWITCH
typedef double myType;
#else
typedef long long myType;
#end
.
.
.
int main()
{
myType a;
#ifdef TYPE_SWITCH
printf ("my value is %lf",a); // I have many printf or scanf and I want to use a simple macro here
#else
printf ("your value is %l",a/10); // I have many printf or scanf and I want to use a simple macro here
#endif
}
You could use something like that:
The compeiler can concate strings while compeiling so you can use
"foo" "bar"to create the string"foobar"the same works for defines. ("foo" PATTERN_INT "bar"would produce"foo%dbar".