ftp.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2002/04/19/06:11:02

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" <eliz AT is DOT elta DOT co DOT il>
Sender: halo1 AT zahav DOT net DOT il
To: "Yong Kwang Goh" <gohyongkwang AT hotmail DOT com>
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: <a9omu0$kgp$1@dahlia.singnet.com.sg> (gohyongkwang@hotmail.com)
Subject: Re: Drawbacks with code optimization?
References: <a9omu0$kgp$1 AT dahlia DOT singnet DOT com DOT sg>
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

> From: "Goh, Yong Kwang" <gohyongkwang AT hotmail DOT com>
> 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

> 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.

- Raw text -

  webmaster     delorie software   privacy  
  Copyright 2019   by DJ Delorie     Updated Jul 2019