Date: Mon, 28 Jul 1997 09:56:18 -0400 (EDT) From: "Art S. Kagel" To: Erik Max Francis Cc: djgpp AT delorie DOT com Subject: Re: optimising In-Reply-To: <33D593DC.16992348@alcyone.com> Message-Id: Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Precedence: bulk On Tue, 22 Jul 1997, Erik Max Francis wrote: > DrkWatr wrote: > > > I was wondering if there is a program that will > > optimisize your c source, and still let you view it as c source? Thus > > allowing me to learn better programming habits. > > Erik Max Francis wrote: > > I know of no such beast. Optimization is generally done at the compiler > level, not the source level. > > Furthermore, such a beast would probably not be all _that_ much use. > Optimization at the source level is highly dependent on the compiler and > platform (for instance, the sizes of the fundamental types) that you're > using. Optimization is better left to the compiler, which 1. is > generating the code in the first place, and 2. has a far better idea of > the environment than any generalized program can. I don't think that DrkWatr is looking for that kind of 'Optimization' but something that will help him to write better "C". You know the kind of common wisdom that says: for(;;){} is better than while(1){} p=&ar[0]; .... p++ is better than i=0; ... ar[i++]; etc. Sorry to have to agree that there is no such beasty. He needs to get a good "C" book and then keep in mind that many of these 'common wisdom' optimizations are made unneccessary by a good optimizer such as GCC/DJGPP has. Indeed in both of the examples I gave the code GCC generates is at least as good for the 'bad' code as for the 'good' code. Art S. Kagel, kagel AT bloomberg DOT com