study: use checkedint as a drop-in replacement of native long

Q. Schroll qs.il.paperinik at gmail.com
Wed Mar 24 19:29:54 UTC 2021


On Wednesday, 24 March 2021 at 18:38:07 UTC, Gregor Mückl wrote:
> On Wednesday, 24 March 2021 at 17:38:14 UTC, H. S. Teoh wrote:
>> Since there is only one sensible meaning of `a = b = c`...
>
> If I'm reading the spec on expressions right, the compiler is 
> actually free to interpret that as (a = b) = c if it feels 
> particularly adventurous. The evaluation order of assignment 
> operations is explicitly undefined...

You're probably mistaken. Evaluation order does not mean 
associating an expression differently. Assignment is right 
associative in any case:

     a = b = c

is the same as

     a = (b = c)

but when *evaluating* a, b, and c, the compiler can choose to 
evaluate e.g. b first. It makes more sense if you look at 
functions retuning by `ref`:


     int _a, _b, _c;
     ref int a() { return _a; }
     ref int b() { return _b; }
     ref int c() { return _c; }

Then, in (parentheses are optional in D)

     a() = (b() = c())

the compiler could execute b() first, a() second and c() last, 
getting references (i.e. pointers) and assigning them in the 
associated way.


More information about the Digitalmars-d mailing list