Is the behaviour of shift expressions with negative left operands defined / portable?
H. S. Teoh
hsteoh at quickfur.ath.cx
Tue Apr 28 20:46:32 UTC 2020
On Tue, Apr 28, 2020 at 08:30:27PM +0000, Harry Gillanders via Digitalmars-d-learn wrote:
> The spec doesn't seem to explicitly mention what happens when the left
> operand of a shift expression is signed and negative. [1]
> But I know that D follows C's semantics for this sort of stuff, and
> the C standard specifies that the result of a negative left operand is
> undefined for `<<`, and implementation-defined for `>>`. [2][3]
[...]
Yes, it's UB. Don't do it.
T
--
One Word to write them all, One Access to find them, One Excel to count them all, And thus to Windows bind them. -- Mike Champion
More information about the Digitalmars-d-learn
mailing list