weird C behavior

Chris Torek chris at umcp-cs.UUCP
Sun Mar 30 09:32:09 AEST 1986


In article <2194 at watdcsu.UUCP> broehl at watdcsu.UUCP (Bernie Roehl) writes:
>In article <436 at umcp-cs.UUCP> chris at umcp-cs.UUCP (Chris Torek) writes:
>>On a 16 bit machine, this should read
>>
>>	printf("%ld\n", 36864);		[me]
>
>Both are wrong on a 16 bit machine, and both will produce garbage (though
>probably different garbage).

False.  I have already explained why, with references to K&R and an
old X3J11 draft.

>What you want is
>
>        printf("%ld\n", 36864L);	[Bernie]

I agree that this is considerably better in practice.  In fact, I
would not at all mind a compiler that gave warnings whenever an
unsuffixed constant did not fit in an integer and was promoted to
long (or unsigned long for `U' suffixed and hex and octal constants,
per X3J11).
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 1415)
UUCP:	seismo!umcp-cs!chris
CSNet:	chris at umcp-cs		ARPA:	chris at mimsy.umd.edu



More information about the Comp.lang.c mailing list