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

Gregor Mückl gregormueckl at gmx.de
Wed Mar 24 21:38:20 UTC 2021


On Wednesday, 24 March 2021 at 19:29:54 UTC, Q. Schroll wrote:
> 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.

Right, I've made a mistake and confused order of evaluation and 
associativity in my first look at the spec. Oops :(

Still, I think that this part the spec isn't actually well 
written. I'm mostly referring to the section on order of 
evaluation, but the rest of this page is also relevant: 
https://dlang.org/spec/expression.html#order-of-evaluation

What I'm missing is a clear statement about operator 
associativity and operator precedence for expressions. When I'm 
reading the spec without applying any additional common sense, a 
+ b * c could be evaluated strictly from left to right because I 
don't see how mathematical operator precedence is explicitly 
established anywhere. Neither do I see associativity established 
anywhere. If assignment was clearly defined to be 
right-associative, things would be unambiguous.




More information about the Digitalmars-d mailing list