optimization (was Re: volatile)

der Mouse mouse at mcgill-vision.UUCP
Wed May 18 18:07:20 AEST 1988


In article <529 at wsccs.UUCP>, terry at wsccs.UUCP (Every system needs one) writes:
> In article <375 at m3.mfci.UUCP>, root at mfci.UUCP (SuperUser) writes:
>> No, these two programs are not equivalent.  When comparing an
>> unsigned to a signed integer, the signed integer is first cast to
>> unsigned [...]
> In addition, since the size of int is defined to be the register
> size,

The size of an int is defined to be whatever the compiler designer
wants it to be.  Generally, this will be a `natural' size of the
machine, such as the register size or the bus width.

> unless the size of int is 8 bits,

Who says a char is 8 bits?  Suppose char and int are both 16 bits?  (As
far as I can tell, the programs are equivalent exactly when char is
narrower than int.)

> the unsigned char will be sign-extended to int

If it gets extended at all, it will be zero-extended.  Pre-ANSI, it
would be zero-extended to unsigned int (generally); post-ANSI (and
probably in a few pre-ANSI compilers) it will be zero-extended to
signed int.

					der Mouse

			uucp: mouse at mcgill-vision.uucp
			arpa: mouse at larry.mcrcim.mcgill.edu



More information about the Comp.lang.c mailing list