weird C behavior

Andrew Koenig ark at alice.UucP
Fri Mar 28 00:52:59 AEST 1986


>>The code contains the following [paraphrased]:
>>	printf("%d\n", 36864);
>>On a 16 bit machine, this should read
>>	printf("%ld\n", 36864);
>>One alternative is to change Ed's original program to read
>>	#define BIG ((int) 36864)

> Passed arguments should always be passed as an "int", I do believe.

Absolutely not!  Are you really suggesting there's no way to pass
a long integer to a function?  The following are correct:

	printf("%d\n", 1);
	printf("%ld\n", 1L);		/* long constant */
	printf("%ld\n", (long) 1);	/* long constant expression */

The following are incorrect:

	printf("%d\n", 1L);
	printf("%ld\n", 1);
	printf("%d\n", (long) 1);

This one is correct on some machines but not on others:

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

because 36864 is an int on some machines and a long on others.



More information about the Comp.lang.c mailing list