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


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.  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.
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.

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


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