Code: Select all
int a = 1;
a = a += a++;
//and
a = a += ++a;Logically, what would you expect the final values of a to be after both of those two expressions?
Now go off and try it... in a handful of different languages.
Moderator: General Moderators
Code: Select all
int a = 1;
a = a += a++;
//and
a = a += ++a;First I'd expect the leading a= to be irrelevant in both cases. And then I expect the pre/post-increment to happen immediatly before/after the involved operands are pushed onto the stack.d11wtq wrote:Logically, what would you expect the final values of a to be after both of those two expressions?
load a [a=1, stack=1]a += a++
load a [a=1, stack=1]a += ++a++
Code: Select all
$a = 1;
$a = $a += $a++;
//3
$a = 1;
$a = $a += ++$a;
//4Code: Select all
Integer a;
a = 1;
a = a += a++;
//2
a = 1;
a = a += ++a;
//3Code: Select all
var a;
a = 1;
a = a += a++;
//2
a = 1;
a = a += ++a;
//3Code: Select all
$a = 1;
$a = $a += $a++;
//3
$a = 1;
$a = $a += ++$a;
//4Code: Select all
int a = 1;
a = a += a++;
//3
int a = 1;
a = a += ++a;
//4Code: Select all
#include <stdio.h>
void main() {
int a = 1;
a = a += a++;
printf("%d\n", a);
}Code: Select all
gcc -fdump-tree-gimple -c testIncrement.cCode: Select all
main ()
{
int a;
a = 1;
a = a + a;
a = a;
a = a + 1;
printf (&"%d\n"[0], a);
}Code: Select all
#include <stdio.h>
void main() {
int a = 2;
int b = 3;
a = b = b++ * a;
printf("%d %d\n", a, b);
}and the gimple code is6 7
Code: Select all
main ()
{
int a;
int b;
a = 2;
b = 3;
b = b * a;
a = b;
b = b + 1;
printf (&"%d %d\n"[0], a, b);
}