[Bug c/78135] In an unsigned long (64 bit) 1<<31 gives rubbish

jmdh01 at btinternet dot com gcc-bugzilla@gcc.gnu.org
Thu Oct 27 17:46:00 GMT 2016


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78135

--- Comment #4 from John Hunter <jmdh01 at btinternet dot com> ---
The annotation of Constants with `ul' is a fudge. In the specimen program,
a constant (1) is assigned to an unsigned long variable (wk) which forces it to
be `ul'. The optimiser, in trying to eliminate a local intermediate variable
inconveniently "forgets" the intrinsic properties of the values in wk. This
makes it an invalid optimisation since it no longer translates the original
intentions of the programmer. (I am sure that Bill Waite would call this a
bug).
I have my K&R chapter 2 p41 open in front of me. It states quite clearly:

"char and short are converted to int, and ...

 Otherwise if either operand is long, the other is converted to long and the
result is long.
 Otherwise if either operand is unsigned, the other is converted to unsigned
and the result is unsigned. ... "


More information about the Gcc-bugs mailing list