This is the mail archive of the gcc@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]

Re: c++ >> and signed numbers?


Jerry Quinn wrote:
According to the c++ spec, operator >> is implementation-defined as to
what it does with negative numbers.  So, does g++ sign-extend negative
numbers shifted to the right?  Or is it triplet-specific?

It is undocumented, and thus no result is guaranteed.


The intent is that the right shift sign-extends negative numbers (assuming we have a signed type). We convert it to a sign-extend shift in the intermediate language (IL), and we expect that the target will emit a sign-extending shift instruction. for this IL construct. However, no where do we guarantee this.

In practice, I don't know of any gcc target that doesn't follow this convention, and I would be very surprised to see one.
--
Jim Wilson, GNU Tools Support, http://www.SpecifixInc.com



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