Is this a stupid hack or a clever hack?
Is it a "hack" at all?
=============== =====
#include <stdio.h>
/* !!HACK!! */
/* no parenthesis on the #define'd expression */
#define MY_FLOAT_CONSTA NT_HACKED 15 / 4
int main(void)
{
printf("The value is %d.\n", 100 * MY_FLOAT_CONSTA NT_HACKED); /* !!
HACK!! */
return 0;
}
=============== =
Is it so much better to do it the proper way, which implies a few type
conversions, implicit and explicit?
#define MY_CONSTANT 3.75
printf( "%d\n", (int)(100 * MY_CONSTANT) );
Thanks
Is it a "hack" at all?
=============== =====
#include <stdio.h>
/* !!HACK!! */
/* no parenthesis on the #define'd expression */
#define MY_FLOAT_CONSTA NT_HACKED 15 / 4
int main(void)
{
printf("The value is %d.\n", 100 * MY_FLOAT_CONSTA NT_HACKED); /* !!
HACK!! */
return 0;
}
=============== =
Is it so much better to do it the proper way, which implies a few type
conversions, implicit and explicit?
#define MY_CONSTANT 3.75
printf( "%d\n", (int)(100 * MY_CONSTANT) );
Thanks
Comment