postincrement behaviour (differences between dmd and gdc)

Nicolai Waniek no.spam at thank.you
Wed Jan 24 14:21:14 PST 2007


> Based on the definition above, I think that the example is equivalent to
> ...
> 
>   int x = 5;
>   int temp;
> 
>   // x = x++;
>   temp = x;  // temp is now 5
>   x = x + 1; // x is now 6
>   x = temp;  // x is now 5
> 
>   // x = x++;
>   temp = x;  // temp is now 5
>   x = x + 1; // x is now 6
>   x = temp;  // x is now 5
> 
> The key phrase is "returns the value and then increments" which I take it
> to mean that it returns the value of the variable that it had prior to it
> being incremented.
> 

I interpret it that way:

"first do everything related to the 'return' part, afterwards
increment". therefore, 7 would be the right solution, because in the
first step, 5 is the return value and is assigned to x, afterwards and
as the final step, x is incremented...

;)



More information about the Digitalmars-d mailing list