compile with gcc option -O0 or -O

David Brown david@westcontrol.com
Mon Sep 19 10:32:00 GMT 2011


On 19/09/2011 11:56, zou wonder wrote:
> Hi All:
>    i have just enable -Wall -Wextra. but seem there is no any useful
> infomation. just some things like:
> <snip>
>
>
>
>
>
> I am wondering now,  Could i add the optimization options which is
> enable by -O one by one?
>
> by then, hope i could find which optimization option affect my code?
>
> but I do not know what is the difference options which is owned just by -O?
>
>

The gcc manual shows quite clearly which individual optimisation flags 
are enabled by -O1 (and other -O options).  However, what it doesn't say 
very well is that there is a huge difference between -O1 and just using 
the flags by themselves - using -O (other than -O0) turns on the 
fundamental optimisation engine in gcc, and thus is much more than just 
a series of optimisation flags.  So you cannot use -O0 and enable these 
flags one by one.  On the other hand, you /can/ enable -O1 and /disable/ 
specific optimisations one by one until the code is working again.

However, since the warning flags haven't helped spot anything obvious, 
your best plan is to do as suggested by Ian in his first reply - make a 
small self-contained example that demonstrates your problem.  In many 
cases, that exercise is enough to let you spot the problem yourself. 
Failing that, you have something you can post and other people can try, 
so that others can help you better.



> thanks again.
>
> On Fri, Sep 16, 2011 at 5:47 PM, Jonathan Wakely<jwakely.gcc@gmail.com>  wrote:
>> On 16 September 2011 10:12, zou wonder wrote:
>>> hi david:
>>> i have tried to enable all the warning option you provided :
>>> and here are some warnings:
>>
>> As Miles said, many of the warning options David suggested are not
>> suitable for all code, you will get most of the benefit just using
>> -Wall -Wextra
>>
>




More information about the Gcc-help mailing list