V
vex
#include <stdio.h>
int main()
{
int a = 1;
int b;
b = a++;
printf( "%d\n", b );
}
gives 1, as you might expect. However;
#include <stdio.h>
int main()
{
int a = 1;
a = a++;
printf( "%d\n", a );
}
gives 2 in the Microsoft compiler, and 1 in the Digital Mars compiler.
I would argue that it should give 1, because "a++" should return 1,
and the postincrement should occur before the assignment, so the value
1 should be assigned to a. Therefore the answer should be 1.
This is some sort of strange evaluation order question, isn't it?
Where the answer is undefined and the standard doesn't say what should
happen? Or did Microsoft mess up ? I like Digital Mars's
behaviour better than the Microsoft compiler in this case.
(celci)
int main()
{
int a = 1;
int b;
b = a++;
printf( "%d\n", b );
}
gives 1, as you might expect. However;
#include <stdio.h>
int main()
{
int a = 1;
a = a++;
printf( "%d\n", a );
}
gives 2 in the Microsoft compiler, and 1 in the Digital Mars compiler.
I would argue that it should give 1, because "a++" should return 1,
and the postincrement should occur before the assignment, so the value
1 should be assigned to a. Therefore the answer should be 1.
This is some sort of strange evaluation order question, isn't it?
Where the answer is undefined and the standard doesn't say what should
happen? Or did Microsoft mess up ? I like Digital Mars's
behaviour better than the Microsoft compiler in this case.
(celci)