more questions about efficient C code

Henry Spencer henry at utzoo.UUCP
Sun Jun 30 08:50:44 AEST 1985


> Seriously, the difference in the fopen call is pretty small, but
> the difference in something like
> 
> 	for (...)
> 		for (...) {
> 			if ((j = (k >> 2) - m) == 0)
> 				k++;
> 		}
> 
> can be important.  Once you get into the habit of testing the results
> of an assignment, it doesn't even look funny anymore.

Retch.  To quote the "Indian Hill C Style" paper:

	For example, the code:
	.DS
	a = b + c;
	d = a + r;
	.DE
	should not be replaced by
	.DS
	d = (a = b + c) + r;
	.DE
	even though the latter may save one cycle.
	Note that in the long run the time difference between the two will
	decrease as the optimizer gains maturity, while the difference in
	ease of maintenance will increase as the human memory of what's
	going on in the latter piece of code begins to fade...
-- 
				Henry Spencer @ U of Toronto Zoology
				{allegra,ihnp4,linus,decvax}!utzoo!henry



More information about the Comp.lang.c mailing list