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

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



On Wed, Jun 11, 2003 at 11:30:00PM -0400, Phil Edwards wrote:
} [gcc-gnats@gcc.gnu.org removed; no bug was added to the gcc database,
} since the email was malformed]
} 
} On Tue, Jun 10, 2003 at 10:32:09PM -0400, Matteo Frigo wrote:
} > >Description:
} > 
} > It would be nice if this function issued a warning because of the
} > implicit conversion ptrdiff_t -> int:
} > 
} > 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.
[...]

Actually, there may be a conversion depending on how wide ptrdiff_t is. If
it is the same width as int (and ptrdiff_t is typically typedef'd to int
in such cases) there is no problem. If int is smaller than ptrdiff_t, such
as with 64-bit addressing on systems with 32-bit ints, there may be an
overflow when converting ptrdiff_t to int.

Importantly, however, this feature request is unnecessary. The desired
feature already exists. See the documentation of the -Wconversion flag.

--Greg



Reply to: