On 2018-08-18 02:35:19 +0100, 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. Yes, but I know how to read a manual. :) What I wanted to know is why there is such a warning for the case where the target integer type is larger than the pointer type. > 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. Yes, this is what I've done, but the (minor) drawback is that I would no longer get a warning if there is a cast to an integer type smaller than the pointer type. > > > Why not use uintptr_t instead? > > > > Because this is not portable: "These types are optional." > > > > Another reason is that the code needs to support C90 compilers > > (and if uintmax_t is not available, there is a fallback to > > unsigned long long, else unsigned long). > > So you could try uintptr_t first and if that's not available, try > uintmax_t, then the other fallbacks. But that would make the code uselessly more complicated (another configure test...). -- Vincent Lefèvre <vincent@xxxxxxxxxx> - Web: <https://www.vinc17.net/> 100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/> Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)