SQLite Forum

Off-by-one in testing.html
Your predicate is correct but your conclusion is incorrect.

On a processor only using the bottom 5 bits of the shift-count register that contained the value of 32, the shift would be 0.  On a processor using at least 6 bits of the shift-count register and where the target register is 32-bits, and the shift is unsigned (the sign is not preserved or extended) then the result would be 0.  Mutatis mutandis for other bit lengths.

Note that a shift of count 32 bits on a 64-bit register would not result in 0.  Note also that it depends on the particularities of the shift operation -- is it a shift that does not affect the sign bit or is sign extending or is it a strictly binary (unsigned) shift?  Is it shifting though the carry bit?

Since the compiler has to be able to implement shift operation on the target platform, and the target platform is variable, the definition of a low-level language like C cannot define what will happen in such circumstances.

This limitation does not apply to most High Level Languages such as FORTRAN or COBOL or PL/1, for example, because the language definition is at a High Level and it is the job of the compiler to "make it so" on whatever CPU claims to support the language.

C and its derivatives, however, are merely a symbolic representation of machine code and the compiler does not really do very much of anything at all.  Once you get into High Level Languages you have gobs of runtime library support to get around differences.  This is the primary reason why COBOL and FORTRAN are the most portable languages ever created.