This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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. ... "

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]