X-Authentication-Warning: delorie.com: mailnull set sender to djgpp-bounces using -f Date: Fri, 19 Apr 2002 12:58:44 +0300 From: "Eli Zaretskii" Sender: halo1 AT zahav DOT net DOT il To: "Yong Kwang Goh" Message-Id: <1884-Fri19Apr2002125843+0300-eliz@is.elta.co.il> X-Mailer: emacs 21.2.50 (via feedmail 8 I) and Blat ver 1.8.9 CC: djgpp AT delorie DOT com In-reply-to: (gohyongkwang@hotmail.com) Subject: Re: Drawbacks with code optimization? References: Reply-To: djgpp AT delorie DOT com Errors-To: nobody AT delorie DOT com X-Mailing-List: djgpp AT delorie DOT com X-Unsubscribes-To: listserv AT delorie DOT com Precedence: bulk > From: "Goh, Yong Kwang" > Newsgroups: comp.os.msdos.djgpp > Date: Fri, 19 Apr 2002 16:38:08 +0800 > > Any drawbacks with turning on optimization when generating a production copy > for distribution for usage? Yes: you are distributing a program different from the one you debugged. > Is there a possibility that the compiler may mis-interprete the original > program logic and rearrange the codes such that the program doesn't work as > expected with optimization turned on, even though the program source is > clearly OK? That would be a bug in the compiler, so its probablility should be low (unless you use some unreleased development snapshot). But there's a much more probable cause for such a program to become broken: optimized code can reveal bugs in your program that unoptimized code didn't. Optimizations rearrange code and data in a way that is supposed to produce a semantically identical program, but a buggy program is not guaranteed to behave the same way... For this reason someone wise compared debugging unoptimized program, then turning on optimizations before shipping the final version to a diver who learns in shallow water with all the safety gear on, then throws away the safety gadgets when diving for real in deep water. It simply doesn't make sense to do that. Why don't you use optimizations during development and debugging? Unlike other compilers, GCC allows you to use -O2 and -g together, so you don't need to make a painful compromise between these two. > How do we determine the level of optimization that is appropriate or > suitable for a program, apart from experimentation? -O1, -O2 or -O3? The best default is -O2. Beyond that, you will need to profile and experiment, but don't expect any speedups more than 10-15% from playing with optimization switches. See section 14.2 of the DJGPP FAQ list for more about this.