Sorry for the delay in replying to this one, I don't read hugs-users very
often...

George Russell writes:
> "Julian Seward (Intl Vendor)" wrote:
> [snip]
> > I don't think it's valid to ask for a shift of 32 or more
> > bits; isn't that undefined behaviour in C and hence in GHC's
> > implementation?
> _Is_ it undefined behaviour in C for unsigned ints (== Word32)? 

Yes.  Things you can't rely on in ANSI C include:

        - shifting signed quatities to the right

        - shifting anything by a number of bits greater than
          or equal to the size of the object being shifted,

        - shifting by a negative amount

I had to change GHC's shift primitives a while back so they behave
reasonably on shifts greater than the word size.  I believe shifts on x86
are always performed modulo the word size in bits, so that's what you're
seeing on Hugs: a shift of 32 is the same as a shift of 0.  I propose that
we define shift right in GHC/Hugs as follows:

        - shifting by more than the word size of the object
          being shifted is defined as 0 for unsigned quatities
          and positive signed quantities, and -1 for negative
          signed quantities.


Cheers,
        Simon

Reply via email to