Hacker News new | ask | show | jobs
by ape4 980 days ago
Honest question, would `V *= Factor` be faster?
1 comments

In almost all cases: no.

"A compound assignment of the form E1 op= E2 differs from the simple assignment expression E1 = E1 op (E2) only in that the lvalue E1 is evaluated only once." (C99, 6.5.16.2p3)

It only matters when evaluating E1 has side effects. For example, `a[i++] += 1;` which is equivalent to `a[i] = a[i] + 1; i++;` rather than `a[i++] = a[i++] + 1;`.

> `a[i++] = a[i++] + 1;`

This is probably not what you want, as "i" is increased twice.

That's why it matters in that situation, because it changes what actually happens (not just the performance).