SUN C compiler bug?

jsdy at hadron.UUCP jsdy at hadron.UUCP
Sat Mar 29 17:49:57 AEST 1986


In article <5418 at sri-spam.ARPA> argv at sri-spam.ARPA (AAAARRRRGGGGv) writes:
>    char x;
>    for(x = 0; x < 128; x++)
>	putchar('x');
>on the sun, the variable x is signed and NOT converted to an int ...
>this program on a sun will produce nothing. On the vax, it will print 128 x's. 

It seems pretty clear that 128 is a numeric constant, not a character
constant.  Therefore, x should be converted to an int or unsigned int
(K&R 2.7, A.6.1; X3J11 3.1).  Which one (int or u_int) seems to be
irrelevant, given a character size >= 8 bits.  Unless the int size is
8 bits too, this behaviour is clearly incorrect.

>    int x;
>    for(x = 0; x < 4294967296; x ++)
>	putchar('x');
>this, too will also print nothing because 4294967296 is -1 and 'x' is
>signed.  Why is there a difference and who is "wrong"?

Here, x is clearly a signed integer.  The constant is too long to
fit into an int, and hence (as I've just learned!) is a long int ...
which is the same as an int on VAXen.  x is "promoted" to long int
(ha ha), and the two are compared, with the result you name.  All
kosher, per the standard(s).
-- 

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



More information about the Comp.lang.c mailing list