op= construction

Andrew Koenig ark at alice.UucP
Tue Jun 10 12:41:26 AEST 1986


>	Quick question-

>	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.

Easy -- your compiler is broken.

	total[i++] += f;

should be equivalent to

	total[i] += f;
	i++;

If it isn't, your compiler is busted.  Simple as that.



More information about the Comp.lang.c mailing list