Strange GCC warnings

Programming, for all ages and all languages.
Post Reply
Candamir

Strange GCC warnings

Post by Candamir »

I recently switched to GCC 4.1.0 (under Cygwin, but shouldn't be relevant, though) and now my kernel won't compile because of the warnings I get (-Wall -Werror set). All those warnings are of the same format:

Code: Select all

[filename]:[line]: warning: pointer targets in (passing argument [argnum] of [funcname]/initialization) differ in signedness.
I checked the warnings and they all refer to the seemingly incorrect use of some variables of type unsigned char * (only pointers, unsigned chars work normally). I also checked the funcion parameter lists and there isn't any error at all, both are unsigned...

I think that this is a new feature introduced in GCC 4.x, because I googled about it and found some information in GNOME mailing-lists and they had the same problem, but they managed to fix it (and didn't post the solution >:( ;)). Has anyone else been migrating to a newer GCC version recently and found himself in front of this problem?

Thanks
durand
Member
Member
Posts: 193
Joined: Wed Dec 21, 2005 12:00 am
Location: South Africa
Contact:

Re:Strange GCC warnings

Post by durand »

Dunno but if it's an signedness issue and you're using unsigned char*, try using just a char* ... or make sure you're casting correctly to the right sign.

GCC 4.0 adds a lot of additional checks and warnings. It's quite nice... it shows you exactly where you have the potential for logical mistakes.
Candamir

Re:Strange GCC warnings

Post by Candamir »

It worked! Just used char * variables when using strings. But anyway, /how/ did this happen? Why a warning about this? unsigned ints/longs didn't make any trobule at all...
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:Strange GCC warnings

Post by Candy »

Because an unsigned int isn't a signed int and they should be incompatible. You can also explicitly cast them or just use unsigned char *'s everywhere. Or do as I do, define a new type (such as the standard uint8_t or my own byte) to refer to an unsigned char.
Candamir

Re:Strange GCC warnings

Post by Candamir »

Thank you all.

If you noticed, I'm fighting with my tools lately ;)

Candamir
Post Reply