[comp.sys.mac] "Efficient" C programming

wert@cup.portal.com (robert scott comer) (03/05/89)

>Slow For Loop:
>		for (i = 0; i <= char_count; i++)
>              destn_buffer[i] = *(source_buffer + i);
>
When you write the for loop you give the compiler the best information
about what you are doing. You are also giving the reader of your program
the best information. If you compiler isn't smart enough to get this
right, then poo-poo on it, but that is a reason to switch compilers
rather than pervert your code. BTW, the loop should look like this:

  for (i = 0; i < char_count; i++)
    destn_buffer[i] = source_buffer[i];

If you know that your fine compiler could do better if the index went
the other way, run the loop backwards:

  for (i = char_count - 1; i >=  0; i--) [...]

Also, register declarations might help on stupid C compilers, which
would never get this right without them. Smart C compilers ignore
register declarations.

scott comer