[fpc-devel] bitwise shift oddity a << b
    Adriaan van Os 
    fpc at microbizz.nl
       
    Tue May 19 16:36:01 CEST 2015
    
    
  
Jonas Maebe wrote:
> No, it does not. It only depends on the type. Shifting an uint32_t with 
> value 1 right by 32 bits is undefined. Shifting an uint64_t with value 1 
> right by 32 bits is 0.
As I said, this is absurd, as so many other de-facto bad habits in computing. There should be no 
difference between shifting a value (of any type) right by N bits or shifting the same value (of 
the same type) N-times right by 1 bit. That is not a matter of type but of simple logic.
But, of course, I understand that CPUs implement it wrong and that the compilers writers want to be 
compatible with the CPU doing it wrong. That is probably the most practical solution. But that 
doesn't make it less ludicrous.
Regards,
Adriaan van Os
    
    
More information about the fpc-devel
mailing list