N
Neelesh Bodas
Hello,
Consider this piece of code:
int swap(int &x, int &y)
{
y = (x-y) + (x=y);
}
This code "claims" to swap values of x and y. I gather that this
claims holds true only if (x-y) gets evaluated before (x==y). Since
there is no sequence point at (+), hence I assume that the order of
evaluation of operands of (+) is unspecified and hence the claim's
isn't always true. Is that correct? Or is there a sequence point at
(x=y) which forces the evaluation of (x-y) before it, there by making
the claim always true?
Consider this piece of code:
int swap(int &x, int &y)
{
y = (x-y) + (x=y);
}
This code "claims" to swap values of x and y. I gather that this
claims holds true only if (x-y) gets evaluated before (x==y). Since
there is no sequence point at (+), hence I assume that the order of
evaluation of operands of (+) is unspecified and hence the claim's
isn't always true. Is that correct? Or is there a sequence point at
(x=y) which forces the evaluation of (x-y) before it, there by making
the claim always true?