zahy[dot]bnaya[At]gmail[dot]com wrote:
hello,
I have a constant declared as
#define TABLESIZE 16*15*14*13*12*11*10*9/3 /// 172972800
I tried the following code:
if (TABLESIZE == 172972800)
{
printf("%d\n",518763960%172972800);
printf("%d\n",518763960%TABLESIZE);
printf("%d\n",TABLESIZE);
}
My output is:
172818360
86486400
172972800
How can it be?
Macros are evil.
Rule 1* is to always put it in brackets:
#define TABLESIZE (16*15*14*13*12*11*10*9/3)
Macros are text replacement so your second printf expands to:
printf("%d\n",518763960%16*15*14*13*12*11*10*9/3);
Rule one comes after at least 3 other rules, which essentially all say:
Don't use macros!
Ben Pope
--
I'm not just a number. To many, I'm known as a string...