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


David Brown <david@westcontrol.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.
>
> 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
...

... but be a bit wary of any warning option which isn't included in
-Wall or -Wextra -- they're usually omitted for a reason (typically
because they yield tons of false positives on reasonable code).

-Miles

-- 
Conservative, n. A statesman enamored of existing evils, as opposed to a
Liberal, who wants to replace them with new ones.


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