jmg@cernvax.UUCP (jmg) (03/03/86)
Maybe this problem is known across the water, but it caused me pain and
suffering, not to mention complaints from the family that I was on that
bl--dy computer again. Anyway, with Trim as distributed on my C-power
version 2.9 compiler it seems that the statement
if (!(bitval & 1))
goes the wrong way when bitval (an int) is hex 100, 200, 400 etc.
Some of you could verify it with
main()
{ int bitval;
char bit;
for (bit=0 ; bit<15 ; bit++)
{ printf("bit = %2d, bitval = %4x\n",bit,bitval);
if (!(bitval & 1))
printf("!(%4x & 1) = %4x is true\n",bitval,!(bitval & 1));
else
printf("!(%4x & 1) = %4x is false\n",bitval,!(bitval & 1));
}
}
It is correct before trimming, wrong after!
Also, does anyone know the exact circumstances under which one gets
a syntax error for something like
i = x[j = y];jmg@cernvax.UUCP (jmg) (03/03/86)
Whoops: I forgot a line in my program: needs to set bitval = 1 << bit
main()
{ int bitval;
char bit;
for (bit=0 ; bit<15 ; bit++)
{ bitval = 1 << bit;
printf("bit = %2d, bitval = %4x\n",bit,bitval);
if (!(bitval & 1))
printf("!(%4x & 1) = %4x is true\n",bitval,!(bitval & 1));
else
printf("!(%4x & 1) = %4x is false\n",bitval,!(bitval & 1));
}
}
Who spotted this deliberate mistake?