Re: Understanding the Behavior of i + ++i in D Language

2024-08-28 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, August 28, 2024 3:44:59 PM MDT Johann Lermer via Digitalmars-d- learn wrote: > On Friday, 23 August 2024 at 08:58:16 UTC, Me'vâ wrote: > > writeln("Result: ", i + ++i); > > I would definitely expect 11 as result (but I still have K&R on > my book shelf, maybe I'm a bit biased). So

Re: Understanding the Behavior of i + ++i in D Language

2024-08-28 Thread Johann Lermer via Digitalmars-d-learn
On Friday, 23 August 2024 at 08:58:16 UTC, Me'vâ wrote: writeln("Result: ", i + ++i); I would definitely expect 11 as result (but I still have K&R on my book shelf, maybe I'm a bit biased). So, when you get 12 with C, I would consider that an error.

Re: Understanding the Behavior of i + ++i in D Language

2024-08-23 Thread IchorDev via Digitalmars-d-learn
On Friday, 23 August 2024 at 09:49:27 UTC, Nick Treleaven wrote: On Friday, 23 August 2024 at 09:42:38 UTC, Nick Treleaven wrote: C++: undefined, could be `6 + 6` if the increment is done first. g++ gives me a warning with `-Wall`: You asked about C, for some reason I used C++. I think the `

Re: Understanding the Behavior of i + ++i in D Language

2024-08-23 Thread Nick Treleaven via Digitalmars-d-learn
On Friday, 23 August 2024 at 09:42:38 UTC, Nick Treleaven wrote: C++: undefined, could be `6 + 6` if the increment is done first. g++ gives me a warning with `-Wall`: You asked about C, for some reason I used C++. But it's the same in C, and the error happens with `gcc -Wall`.

Re: Understanding the Behavior of i + ++i in D Language

2024-08-23 Thread Nick Treleaven via Digitalmars-d-learn
On Friday, 23 August 2024 at 08:58:16 UTC, Me'vâ wrote: ``` import std.stdio:writeln; void main() { int i = 5; writeln("Result: ", i + ++i); } ``` When I run this, it surprisingly outputs 11. I tried something similar in C before and it gave me 12. I’m curious, why is there a differen