Michael P Friedlander writes: > Thanks for pointing out various options, Andrew. > > >> The behavior of a numerical code I'm working on varies > >> drastically depending on whether I've compiled it with > >> the -g or -O flags. > >> > >> The code's behavior under -g is much more stable, and I'm > >> wondering if the -O flag is exposing a bug that I need to > >> fix. Are there some gcc flags that I should try that might > >> guide me in finding the problem? (I've already tried the > >> obvious -Wall which gives no warnings.) > > > > If your code does something different with/without -g, then that's a > > bug in gcc. -g shouldn't make any difference to the behaviour of your > > program. > > -g makes no difference. > > > If your code does somethig different with -O, that's possibly a gcc > > bug but it's probably a bug in your code. > > -OO and -O give different results. > > > If you use -fno-strict-aliasing and that makes a difference with -O, > > then that's definitely a bug in your code. > > I think you nailed it! With -fno-strict-aliasing, -O0 and -O > give identical results. I tried -fstrict-aliasing with -Wstrict- > aliasing=2, but gcc doesn't issue any warnings. > > Any pointers for how to track this sort of thing down? What kind of > things should I look for? Your code probably contains something like int n; *(short*)&n = 5; i.e. you're accessing an object as something other than its underlying type. However, something as blatant as this would probably be caught by gcc, so you should be looking for something more subtle. Like this, maybe: int n; void *p = &n; *(short*)p = 5; Andrew.