This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Warning for different pointer signedness


Ian Lance Taylor <ian@airs.com> writes:

| Andrew Pinski <pinskia@physics.uc.edu> writes:
| 
| > > It would seem that the change was unnecessary, and possibly even
| > > incorrect,
| > > as although the objects they referance are not of the same signedness,
| > > their pointers (which are the objects being compared) are completely
| > > compatible, as the storage size and alignment they reference is
| > > defined by
| > > the objects storage class (i.e. char, short, int, long, etc.) which
| > > would
| > > seem to be insensitive to the objects signedness, are equivalent.
| > 
| > Wrong, wrong, wrong, the change only moved a warning from -pedantic
| > to always on, in fact some compilers reject the code as it is invalid c.
| 
| My main concern is that it leads to warnings on some uses which are
| valid.  The string routines are defined to do comparisons as though
| the characters were of type unsigned char. 

Yes, that means they springle cast as approppriate, not that an
implicit conversion on pointers is performed.

| So
|     int foo (unsigned char *p) { return strcmp (p, "foo"); }
| will always work correctly. But now the compiler emits an
| unconditional warning.  This seems dubious to me.  The code is safe.

The code looks dubious to me, as in real life it would hardly pass
code-review stage.

| Some coding styles will lead to writing this sort of code.  A cast is
| required here for full language correctness, but not for real-life
| correctness.

Well, there is an infinite amount of "real-life correct" codes that fail
type checking; do you propose a clear guideline that the compiler
should follow to accept them?

| 
| I think it would be entirely reasonable to add this warning to -Wall
| or -Wextra, and of course the warning should always be emitted for
| -pedantic.  But an unconditional warning doesn't seem right.
| 
| Ian

-- 
                                                       Gabriel Dos Reis 
                                           gdr@integrable-solutions.net


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]