On Fri, Sep 16, 2011 at 3:07 AM, David Brown <david@xxxxxxxxxxxxxxx> wrote: > On 16/09/2011 07:40, Ian Lance Taylor wrote: >> >> zou wonder<wonder.zou@xxxxxxxxx> writes: >> >>> but one weird problem is that the following codes compiled with option >>> -O0 >> >> You need to show us a small complete self-contained example. >> >> Normally a program which works at -O0 and fails at -O1 has an >> uninitialized variable somewhere. >> >> Ian >> > > Another common cause is aliasing - using pointer casts to access the same > data in different ways. > > And (especially if this is embedded programming), also check for missing > "volatile" qualifiers. > > Compile your code with lots of warnings - that will help spot mistakes. The > flags I often use are: > > -Wall > -Wextra > -Winit-self > -Wmissing-include-dirs > -Wunused > -Wstrict-overflow > -Wfloat-equal > -Wundef > -Wunsafe-loop-optimizations > -Wpointer-arith > -Wcast-qual > -Wcast-align > -Wwrite-strings > -Wlogical-op > -Wmissing-declarations > -Wmissing-noreturn > -Wmissing-format-attribute > -Winline > -Wnested-externs > -Wdisabled-optimization > -Wunsafe-loop-optimizations > -Wpadded > -Wunreachable-code > -Wmissing-prototypes > -Wredundant-decls > -Wcast-qual > -Wcast-align > -Wpointer-arith > -Wnested-externs > -Wno-multichar -Wformat=2 -Wformat-security? Great use of the tools, though. GCC has some awesome diagnostic capabilities. Jeff