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




> From: Gabriel Dos Reis <gdr@integrable-solutions.net>
> Joe Buck <Joe.Buck@synopsys.com> writes:
> 
> | On Mon, Dec 20, 2004 at 10:21:38PM +0100, Gabriel Dos Reis wrote:
> | > Pointers-to-object comparaison make sense (from the relevant standards
> | > point of view) only if they
> | > 
> | >   (i)   point into the same object; or
> | >   (ii)  are (or one of them is) one-past-the-end of the same object; or
> | >   (iii) are (or one of them is) null.
> | > 
> | > You then realize that if the pointers are not of the same type or cannot
> be
> | > implicitly converted to each other, then the comparison become
> | > invalid.
> | 
> | But there is the interesting fact that pointers that differ only in
> | the signed-ness of the pointed-to object can alias each other.  That
> | seems to imply that testing for equality makes sense, even without casting.
> 
> Are you advocating that we should be accepting this?
> 
>    typedef struct S S;
> 
>    int cmp(S* p, double* q)  { return p == q; }
> 
>    struct S {
>       double m;
>    };
> 
> If not why?  The provision that supports the aliasing rule you're
> alluding to is also the rule that would support the above.
> 
> I think the bottom line is that aliasing is very different from pointer
> comparison, and aliasing is better tested when both pointers are
> casted either to void* or char*.
> 
> -- Gaby

It would seem that it would have been more useful to define pointers
compatible if they reference equivalent effective types; as it's the
basis of determining if an arbitrary object may be modified by it directly.

(which would then preserve useful warnings when attempting to compare
 pointers to nonequivalent effective types, such as between p == q above)




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