[fpc-devel] bitwise shift oddity a << b
Jonas Maebe
jonas.maebe at elis.ugent.be
Mon May 18 23:27:46 CEST 2015
Martin Frb wrote:
> What is supposed to happen if the 2nd argument is negative?
I would propose to document it as "undefined behaviour", just like C
does (http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1124.pdf ,
section 4.5.7). The reason is that the behaviour can differ depending on
the cpu, so if you want to guarantee consistent behaviour on all
platforms, you can no longer just emit a shift left/right instruction
and have to add all kinds of checks.
Maybe we should support emitting range checks for the right operand
though (to give an error if it falls outside the range of shift values
whose behaviour is defined).
Jonas
More information about the fpc-devel
mailing list