Re: warning: comparison between signed and unsigned integer expressions

Clark Cox <[email protected]>
Newsgroups gmane.comp.macosx.devel
Message-ID <[email protected]>
On Tue, Apr 20, 2010 at 1:59 PM, Stephen Hoffman <[email protected]> wrote:
>
> On Mon, 19 Apr 2010 14:21:42 -0700, SD <macosxdevlist-LS+HbC+WUqxt2bImrQXijdAWLNoT+7d/@public.gmane.orgm> asks:
>
>> How do people normally handle the comparison between signed and
>> unsigned integers?  I have cross platform code (Mac and Windows and
>> 32 bit and 64 bit compilations).
>
> With correct typing, or with casting.
>
> With C, promotion of an unsigned can end up as a signed value or as an unsigned value, depending on the value being promoted.

This does not depend on the *value* that is being promoted, but the
*type* being promoted.

> Have a look around for the value-preserving and unsigned-preserving discussions; current C tends to be value-preserving.

The value-preserving behavior is mandated by the C standard wherever possible.

> Depending on how cross-platform your cross-platform code is, another issue that can occur is endianness.
> Mac OS X Intel is little-endian and PPC is big-endian.  Windows is little-endian.  HP-UX and SPARC are big-endian.

FYI: Endian-ness is *never* an issue with this type of conversion.
After the appropriate type is chosen, the conversion itself is done
based on value, not representation.


-- 
Clark S. Cox III
[email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.