On Fri, Feb 17, 2006 at 11:12:40AM -0600, Brian Hurt wrote:
> >The comman operator is used extensively in for loops, to allow two
> >indices to advance in unison.
> 
> This is one of those situations where a lot of people think it's an 
> optimization, but it's not.  Say you're doing:
> 
> for (i = 0, j = k; j < n; i++, j++) {
>     a[i] = a[j];
> };
> 
> On most systems, it's actually *more* efficient to do:
> for (j = k; j < n; j++) {
>     a[j-k] = a[j];
> }

On most systems is more efficient to memmove it but that is beside the
point. I was thinking of other kinds of operations inside the loop,
not a dumb move.

I was never concerned with that level of efficiency but if you write
your loop like you did, you better have a big fat comment with a good
explanation for the eyesore...

> The few times this is really necessary, hoisting one variable up out of 
> the for loop doesn't hurt performance at all.
> 
> Therefor, using the comma operator in the a for loop, even for multiple 
> indicies, is an abuse of the comma operator.

"There is one abuse. Here is one abuse. Therefore most uses are
abuses." You may be generalizing too soon, I'm afraid.

Cheers,
florin

-- 
Don't question authority: they don't know either!
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://mailman.mn-linux.org/pipermail/tclug-list/attachments/20060217/1898b90a/attachment-0001.pgp