Re: warning: comparison between signed and unsigned integer expressions

Stephen Hoffman <[email protected]>
Newsgroups gmane.comp.macosx.devel
Message-ID <[email protected]>
On Mon, 19 Apr 2010 14:21:42 -0700, SD <macosxdevlist-LS+HbC+WUqxt2bImrQXijVaTQe2KTcn/@public.gmane.org> 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.  
Have a look around for the value-preserving and unsigned-preserving discussions; current C tends to be value-preserving.

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.

Requesting diagnostics for portability and standards-compliance and questionable code can be a good idea, too.
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.