[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Feature request: gcc should warn upon conversions ptrdiff_t -> int



On Thu, Jun 12, 2003 at 07:06:42AM +0200, Martin v. L?wis wrote:
> Phil Edwards <phil@jaj.com> writes:
> 
> > > int foo(int *x, int *y)
> > > {
> > >      return x - y;
> > > }
> > 
> > There is no conversion to int.  foo* may be subtracted from foo* for any
> > type foo.  It's normal pointer arithmetic.  This code is fine.
> 
> You are missing the point. The result of the subtraction is of type
> ptrdiff_t (which is fine), but then, on the return, that gets
> converted to int.

Oh, /return/ type.  Yes, I missed that; thanks for pointing it out.

I won't have access to a non-ILP32 system for a couple of weeks, but I'd
be willing to bet that on systems where ptrdiff_t is larger than int,
this code already elicts a warning, probably via -Wconversion.

For platforms where they are the same... eugh.  You'd like a warning on
constructs that "might" cause portability problems, but given that it's
just a typdef, all the semantic analysis routines will simply see two
identical types.  Implementing this would be hard.  Hmmm.


Phil

-- 
If ye love wealth greater than liberty, the tranquility of servitude greater
than the animating contest for freedom, go home and leave us in peace.  We seek
not your counsel, nor your arms.  Crouch down and lick the hand that feeds you;
and may posterity forget that ye were our countrymen.            - Samuel Adams



Reply to: