Article View: comp.sys.mac
Article #38781Re: "Efficient" C programming
From: robert scott comer
Date: Sat, 04 Mar 1989 20:19
Date: Sat, 04 Mar 1989 20:19
23 lines
1437 bytes
1437 bytes
>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
Technical Details
Message-ID:
<15379@cup.portal.com>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.milw.wisc.edu!leah!itsgw!steinmetz!uunet!portal!cup.portal.com!wertReferences:
<IY0io5y00UgPAM2b4a@andrew.cmu.edu> <41a2364a.a590@mag.engin.umich.edu> <70755@ti-csl.csc.ti.com> <41aa5eaa.a590@mag.engin.umich.edu> <15682@versatc.UUCP> <6992@boulder.Colorado.EDU>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.milw.wisc.edu!leah!itsgw!steinmetz!uunet!portal!cup.portal.com!wert From: wert@cup.portal.com (robert scott comer) Newsgroups: comp.sys.mac Subject: Re: "Efficient" C programming Message-ID: <15379@cup.portal.com> Date: 4 Mar 89 20:19:09 GMT References: <IY0io5y00UgPAM2b4a@andrew.cmu.edu> <41a2364a.a590@mag.engin.umich.edu> <70755@ti-csl.csc.ti.com> <41aa5eaa.a590@mag.engin.umich.edu> <15682@versatc.UUCP> <6992@boulder.Colorado.EDU> Organization: The Portal System (TM) Lines: 23