weird C behavior

Chris Torek chris at umcp-cs.UUCP
Thu Mar 27 12:43:39 AEST 1986


In article <330 at hadron.UUCP> jsdy at hadron.UUCP (Joseph S. D. Yao) writes:

>>On a 16 bit machine, this should read
>>	printf("%ld\n", 36864);		[me]

>Passed arguments should always be passed as an "int", I do believe.
>...  Sorry to have to publicly disagree, Chris.

Unfortunately for you, I checked my sources first.  The clue was
there in Ed's original posting.  According to K&R, a constant that
is too big to be an `int' is automatically considered a `long'; on
a 16 bit machine,

	printf("%ld\n", 36864);

and

	printf("%ld\n", 36864L);

build the exact same stack.

For you ANSI C buffs, I quote from a year-old draft (the latest I
could find), section C.1.3.2, `Integer constants':

	If the value of an unsuffixed decimal constant (base 10) is no
	greater than that of the largest signed int, the constant has
	type signed int; otherwise it has type signed long int.

Now, if you were using ANSI C and had written, say,

	void myfunc(int);

	myfunc(36864);

you would get something closer to what you expected. . . .
-- 
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