"++" vs "+=" on function parameter
Timon Gehr
timon.gehr at gmx.ch
Sun Mar 8 03:00:58 UTC 2026
On 3/8/26 03:28, claptrap wrote:
> ```
> module test;
> import std.stdio;
>
> void foo(int pos)
> {
> writeln("inside foo : ",pos);
> }
>
> void main()
> {
> writeln("++");
> int p = 0;
> foo(p++);
> writeln("after foo : ",p);
>
> writeln("+=1");
> p = 0;
> foo(p+=1);
> writeln("after foo : ",p);
> }
> ```
>
> prints:
>
> ++
> inside foo : 0
> after foo : 1
> +=1
> inside foo : 1
> after foo : 1
>
> seems inconsistent to me, probably stuck with it now though I guess?
> ...
`++p` and `p++` are different. If you want to match `p+=1` you should go
with `++p`.
More information about the Digitalmars-d
mailing list