"++" vs "+=" on function parameter

user1234 user1234 at 12.de
Tue Mar 10 02:04:58 UTC 2026


On Sunday, 8 March 2026 at 12:50:35 UTC, Sergey wrote:
> On Sunday, 8 March 2026 at 12:42:19 UTC, Nick Treleaven wrote:
>> On Sunday, 8 March 2026 at 10:26:54 UTC, claptrap wrote:
>>> Doesnt that mean "p++" is inconsistent? Arn't "p++" and 
>>> "p+=1" essentially shorthand for "p=p+1"
>>
>> From https://dlang.org/spec/expression.html#order-increment:
>>
>> ```d
>> Expression	Equivalent
>> ++expr		((expr) += 1)
>> expr++		(ref x){auto t = x; ++x; return t;}(expr)
>> ```
>
> I'm amazed how we have the whole discussion about obvious thing 
> that every high school student who ever learned any C-like 
> language knows :)

that's not necessarily a high schooler thing. The point is "do 
you need the rvalue before the side effect". There is an 
interesting discussion here

https://softwareengineering.stackexchange.com/questions/43067/why-do-we-have-postfix-increment

So apparently the postfix version matches to an instruction in 
the PDP arch ? cool. However even with the common x86 arch you're 
pretty sure that the result will stand in a register, which opens 
doors to optimz. But seriously

```d
(ref x){auto t = x; ++x; return t;}(expr)
```

does not express well that, i.e the "value category" (boring 
topic)


More information about the Digitalmars-d mailing list