On Sat, 18 Aug 2018, Jonathan Wakely wrote:
On Sat, 18 Aug 2018 at 02:22, Vincent Lefevre <vincent+gcc@xxxxxxxxxx> wrote:
On 2018-08-18 00:14:50 +0100, Jonathan Wakely wrote:
On Fri, 17 Aug 2018 at 23:27, Vincent Lefevre wrote:
What's the point of the pointer-to-int-cast warning, which is
enabled by -Wall?
I get this warning under 32-bit Linux when casting a pointer to
uintmax_t. I use uintmax_t to make sure that the integer size is
large enough. So, what's the problem?
sizeof(uintmax_t) != sizeof(void*).
But why would this make the conversion invalid?
The warning doesn't say it's invalid, it says they're different sizes.
I don't know why casting to an integer type that's larger than a
pointer is considered a problem (obviously the other way around is
bad), but you can use -Wno-pointer-to-int-cast if you don't care about
that.
I expect it is "bad" because it isn't clear if the value should be
sign-extended or zero-extended when cast to a larger integer. But that
doesn't really matter if you are only going to convert it back to a
pointer, where the extra bits will disappear. It isn't obvious that it
warrants a warning in -Wall (as opposed to -Wextra or something more
specialized), but if you are trying to use the extra high bits to stuff
some extra information, it may matter that they are not 0.
--
Marc Glisse