op= construction
Doug Gwyn
gwyn at brl-smoke.ARPA
Sun Jun 15 15:46:38 AEST 1986
In article <108 at mruxe.UUCP> cgw at mruxe.UUCP (C Waldman) writes:
- In a loop, an array element is incremented, then the array index
- is advanced to the next element. I recently coded this with
- ....
- total[i++] += f;
- ....
- After a couple of "Memory fault- core dumped" messages, I realized
- that i is getting incremented twice. I broke it into two lines and
- everything was ok, but I'm wondering why this construction doesn't
- work.
Either you were incrementing i somewhere else too (e.g. in the for() head),
or else your compiler has a bug. The whole point of the op= operators is
that the left side is supposed to be evaluated only once.
More information about the Comp.lang.c
mailing list