This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: compile with gcc option -O0 or -O


On 16/09/2011 07:40, Ian Lance Taylor wrote:
zou wonder<wonder.zou@gmail.com> 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





Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]