Order of evaluation for named arguments
matheus
matheus at gmail.com
Thu Apr 3 15:39:24 UTC 2025
On Thursday, 3 April 2025 at 12:40:54 UTC, GrimMaple wrote:
> ...
> ```d
> int t = 1;
> auto z = t++ + ++t;
> ```
> Should explicitly state that:
> ```
> Warning: variable `t` is modified several times within one
> sequence point, consider refactoring.
> ```
>...
For me the real risk is here:
import std;
void foo(int a, int b){
writeln(a+b);
}
void main(){
int t = 1;
t = 1; foo(t++,++t);
t = 1; foo(++t,++t);
t = 1; foo(t++,t++);
}
prints:
4
5
3
Yes I know the problem and the convention and even the appealing
for some people with this pre / pos increment.
But in college I felt the pain for poor people learning and
programming for the first time and facing things like this.
Matheus.
More information about the Digitalmars-d
mailing list