weird C behavior

Joseph S. D. Yao jsdy at hadron.UUCP
Sat Mar 22 19:11:16 AEST 1986


In article <557 at utastro.UUCP> nather at utastro.UUCP (Ed Nather) writes:
>/* weird.c - demonstrate weird C behavior */
>/* Reference: Kernighan and Ritchie pp. 40-41 */
>#include <stdio.h>
>#define BIG 36864
>main()
>{
>int i;
>
>i = BIG;
>if(i == BIG)
>    printf("Equality found: i = %d, BIG = %d\n", i, BIG);
>else
>    printf("Equality NOT found: i = %d, BIG = %d\n", i, BIG);
>}
>Equality NOT found: i = -28672, BIG = -28672

Check the code produced by your compiler.  Could you be mixing
16- and 32-bit operations?  I.e., could the compiler be moving
the BIG word into 16-bit i (making it a negative number), then
(finding that BIG is > 32767) upgrading both to (long) before
the compare?  Check and see.  You don't say what machine or C
you used, so we have no way of telling.
-- 

	Joe Yao		hadron!jsdy at seismo.{CSS.GOV,ARPA,UUCP}



More information about the Comp.lang.c mailing list