This is the mail archive of the
mailing list for the GCC project.
Re: c++ >> and signed numbers?
On Mon, Sep 15, 2003 at 08:10:13PM -0700, Jim Wilson wrote:
> 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.
I believe that the standard has this language because, way back in the 80s,
there were processor architectures that lacked arithmetic right shift
However, the need for the vagueness is in my opinion long gone, and I
think that future versions of the C and C++ standards should just specify
this operation to do what 99.9% of all implementations do.