Shift operator, unexpected result

kinke noone at nowhere.com
Wed Jun 9 19:58:24 UTC 2021


On Wednesday, 9 June 2021 at 19:13:10 UTC, JG wrote:
> I found the following behaviour, as part of a more complicated 
> algorithm, unexpected. The program:
>
>     import std;
>     void main()
>     {
>         int n = 64;
>         writeln(123uL>>n);
>     }
>
> produces:
>
> 123
>
> I would expect 0.
>
> What is the rationale for this behaviour or is it a bug?

This is undefined behavior as in other languages, see §3 in 
https://dlang.org/spec/expression.html#shift_expressions.


More information about the Digitalmars-d-learn mailing list