signed vs unsigned pointer warning

Linus Torvalds torvalds@osdl.org
Tue Sep 21 22:36:00 GMT 2004



On Tue, 21 Sep 2004, Richard Henderson wrote:
>
> [ Forwarded from the thread beginning at
>   http://marc.theaimsgroup.com/?l=linux-sparse&m=109577992701909&w=2
> ]

Btw, please do look at that first email, and in particular about "char".

The fact is, "char" is neither clearly signed nor unsigned, so it looks to
be clearly a bug to complain about assignment either way. Also, "char"  
ends up being special because there are magic language features that are
explicitly "char", but make sense for both signed and unsigned types,
notably constant strings (but also standard-defined string functions like
"strlen()" that are defined in terms of taking a "const char *").

In other words, I'd argue _strongly_ to allow at least "char *" to be
compatible with both "unsigned char *" and "signed char *". Anything else
is just madness.

Making "signed char *" be incompatible with "unsigned char *" (ie
_explicit_ signedness) sounds sane enough, but it may be that gcc can't
tell the difference internally.

Also, can we please add a flag to turn this off? I'd prefer to see
something like "-W[no-]typesign", which is what I already do in sparse (in
sparse it currently defaults to being off pending resolution of whether it
makes sense at all).

As to the argument that signed and unsigned types are incompatible - that
may be true in theory ("C language lawyers"), but it's certainly not true
in practice. I'd hope that practice matters.

		Linus



More information about the Gcc mailing list