weird C behavior

Ed Nather nather at utastro.UUCP
Sat Mar 22 04:29:55 AEST 1986


Here is a short C program which gives correct output according to K & R.
While I can't argue it's wrong, it is not transparently right, either.
The following was extracted directly from the display screen of my
IBM PC.  Try it on *your* 16-bit computer.  Then explain it to a friend.
-----------------------------------------------------------------------
C% print weird.c

/* 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);
}

C% weird

Equality NOT found: i = -28672, BIG = -28672

-----------------------------------------------------------------------
-- 
Ed Nather
Astronomy Dept, U of Texas @ Austin
{allegra,ihnp4}!{noao,ut-sally}!utastro!nather
nather at astro.UTEXAS.EDU



More information about the Comp.lang.c mailing list