Optimization (was Re: volatile)

Dave Cornutt dkc at hotlr.ATT
Fri May 6 06:18:04 AEST 1988


In article <1988May4.195636.1801 at utzoo.uucp> henry at utzoo.uucp (Henry Spencer) writes:
 > > ... This is one hell of an incentive to have
 > > code behave the same way with or without -O!  How do I debug something if
 > > my debugger is only useful when there isn't a problem?  GAAAK!  You mean I
 > > was right when I said before that looking at assembly was still useful?!?
[snotty tone omitted :-)]
 > More seriously, yes, debugging optimized code can be a real pain.  I don't
 > think even the Mips people, who put in a lot of effort on things like this,
 > have a debugger that can explain to you what the optimized code is doing.
 > You just have to tone down the optimization for debugging, and pray that
 > there aren't any serious differences of opinion between you and the optimizer
 > when it comes time to "compile for production".  If that doesn't work, you
 > are indeed reduced to reading the assembler, which could be, um, interesting
 > on something like one of the Multiflow machines.  (Heaven knows it's no
 > picnic even on more orthodox hardware.)
 > 
 > Most anybody who's programmed in C for a long time will have run into things
 > like storage-management bugs that "go away" when you put in debugging...

This got me thinking.  (I know, doesn't happen every day, but...)
"Hmmm", I hmmmed.  "What if the compiler had a 'simulated optimization'
option?  That is, don't actually optimize, but see to it that all of the
little side effects that occur when optimizing are simulated.  For instance,
arrange for all unitilized variables to contain some garbage value instead
of nice convenient zeros; initialize ints to 666, floats to Planck's
constant; character arrays to 'KILROY WAS HERE', and pointers to some
value (not the nil value) that will cause a segmentation violation or
bus error when dereferenced."

Too farfetched?  Or can it be fetched a little nearer?
-- 
Dave Cornutt, AT&T Bell Labs (rm 4A406,x1088), Holmdel, NJ
UUCP:{ihnp4,allegra,cbosgd}!hotly!dkc
"The opinions expressed herein are not necessarily my employer's, not
necessarily mine, and probably not necessary"



More information about the Comp.lang.c mailing list