weird C behavior

Joseph S. D. Yao jsdy at hadron.UUCP
Mon Mar 24 04:34:23 AEST 1986


In article <436 at umcp-cs.UUCP> chris at umcp-cs.UUCP (Chris Torek) writes:
>In article <557 at utastro.UUCP> nather at utastro.UUCP (Ed Nather) writes:
>>Here is a short C program which gives correct output according to K & R.
>>[...]  Try it on *your* 16-bit computer.
>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.
Changing the printf specification will  n e v e r  change what the
C compiler does with the rest of the arguments!!  Nather's original
posting led me to believe he was using some kind of a 16/32 bit
machine, with a C compiler that had not quite been consistent.  I.e.,
on the comparison, all I could think was that a 16-bit int had sign-
extended to compare with an IMPLICIT long constant (look at it: it's
not an explicit long constant!).  This is inconsistent.  However, an
arg has to be explicitly declared; so the int default almost has to
be honoured.

Sorry to have to publicly disagree, Chris.
-- 

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



More information about the Comp.lang.c mailing list