Re: Useless pointer-to-int-cast warning?

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

 



On 2018-08-18 08:01:46 +0200, Marc Glisse wrote:
> 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.

But the C standard says that the behavior is undefined if the result
cannot be represented in the integer type. Thus uintmax_t or intmax_t
is safer than a integer type of the same size of the pointer, in case
the pointer value as an integer would not be representable in this
type, but would be in uintmax_t or intmax_t. So, IMHO, this warning
is just bad.

-- 
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)



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux