GCC 4 and signedness

James Livingston jrl at ids.org.au
Thu Sep 1 05:46:42 UTC 2005

On Wed, 2005-08-31 at 23:44 -0400, Dave Walker wrote:
> I just updated breezy today, and noticed that GCC4 was being installed. 
> Since it has been installed almost all the projects I have been working 
> on, are getting at least 10
> "pointer targets in passing argument 1 of 
> ‘gaim_uri_list_extract_filenames’ differ in signedness"
> or similar. My question is why is it complaining that, in an example of 
> strcmp, I am comparing unsigned char* with a char*? The point is I don't 
> care the sign, all I care about is if they are the same. Or am I missing 
> a very simple thing about signedness?

Comparing signed and unsigned values is normally a mistake, and
potentially the source of some bugs. GCC 4 changed it so that warning
about it is now the default. If you're sure that there are no problems
with comparing things of different signedness, you can just stick some
casts in.

Consider the unsigned char of value 255, and the signed char of value -1
- are these the same?

If you compare their direct representations they are both 0xFF, and
hence the same. However if they undergo type promotion to a wider type
(e.g. a short) their representations will be 0x00FF and 0xFFFF, and
hence not the same. Because type promotion can happens automatically
(and AFAIK arbitrarily), the results of the comparison may depend on
what the compiler feel like doing.


James "Doc" Livingston 
Every now and then, Google doesn't throw up what I need so I start
checking Altavista, Yahoo, etc. In almost every single case, I am
brutally reminded why I use Google in the first place. -- John Riddoch, 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
URL: <https://lists.ubuntu.com/archives/ubuntu-users/attachments/20050901/b513af65/attachment.pgp>

More information about the ubuntu-users mailing list