Optimization (was Re: volatile)

Henry Spencer henry at utzoo.uucp
Thu May 5 05:56:36 AEST 1988


> ... 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?!?
> (Henry, eat your hat!;-)

[begin snotty tone :-)] Well, I suppose people who make errors, and thus
need debuggers, would have to worry about such things, but I fail to see
any reason why *I* should eat my hat...  [end tone] :-) :-)

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...
-- 
NASA is to spaceflight as            |  Henry Spencer @ U of Toronto Zoology
the Post Office is to mail.          | {ihnp4,decvax,uunet!mnetor}!utzoo!henry



More information about the Comp.lang.c mailing list