compile with gcc option -O0 or -O

David Brown david@westcontrol.com
Fri Sep 16 09:32:00 GMT 2011


On 16/09/2011 11:12, zou wonder wrote:
> hi david:
> i have tried to enable all the warning option you provided :
> and here are some warnings:
>

As I mentioned in another post, those were warning flags /I/ use, and 
may not suit other people's code.  In particular, you want to disable 
flags for warnings that don't affect the correctness of the code but 
lead to lots of warnings.  In your case here, all the warnings have come 
from two flags: -Winline, and -Wpadded.

-Winline warns you when the compiler does not inline a function that is 
otherwise marked for inlining (either explicitly, or implicitly from a 
class definition).  Normally I would say that this indicates that 
something is not happening as you expect it to, perhaps due to an error 
in your code.  But as gcc gets steadily smarter, it finds good reasons 
to ignore the "inline" hint.

-Wpadded warns when structs have extra space added for alignment 
purposes.  For the type of code I write, if there is extra space in the 
struct then I've made a mistake in the definition, so I like this 
warning.  For many other types of code, the warnings are just annoying 
noise.  It really depends on whether the struct has to match an existing 
external structure, or if it is only used within the program.

So remove these two and compile again.  Alternatively, begin with just 
"-Wall -Wextra" and see if they help you spot your mistake - most code 
should compile cleanly with these enabled.

mvh.,

David



>                  from xmmmapte.cc:3:
> /work/smsc/include/stlport/stl/_ostream.h:357: warning: inlining
> failed in call to ‘stlpmtx_std::basic_ostream<_CharT, _Traits>&
> stlpmtx_std::endl(stlpmtx_std::basic_ostream<_CharT, _Traits>&) [with
> _CharT = char, _Traits = stlpmtx_std::char_traits<char>]Â’: call is
> unlikely and code size would grow
> /work/smsc/include/stlport/stl/_ostream.h:78: warning: called from here
> In file included from xmmmapte.cc:3:
> /work/smsc/include/stlport/stl/_string.h: In function ‘void
> set_map_perror_from_report_cause(VARIABLE_STR*, VTASK*)Â’:
> /work/smsc/include/stlport/stl/_string.h:372: warning: inlining failed
> in call to ‘stlpmtx_std::basic_string<_CharT, _Traits,
> _Alloc>::~basic_string() [with _CharT = char, _Traits =
> stlpmtx_std::char_traits<char>, _Alloc =
> stlpmtx_std::allocator<char>]Â’: call is unlikely and code size would
> grow
> xmmmap.cc:2166: warning: called from here
> /work/smsc/include/stlport/stl/_string.h:372: warning: inlining failed
> in call to ‘stlpmtx_std::basic_string<_CharT, _Traits,
> _Alloc>::~basic_string() [with _CharT = char, _Traits =
> stlpmtx_std::char_traits<char>, _Alloc =
> stlpmtx_std::allocator<char>]Â’: call is unlikely and code size would
> grow
> xmmmap.cc:2166: warning: called from here
> /work/smsc/include/stlport/stl/_string.h:372: warning: inlining failed
> in call to ‘stlpmtx_std::basic_string<_CharT, _Traits,
> _Alloc>::~basic_string() [with _CharT = char, _Traits =
> stlpmtx_std::char_traits<char>, _Alloc =
> stlpmtx_std::allocator<char>]Â’: call is unlikely and code size would
> grow
> xmmmap.cc:2166: warning: called from here
> /work/smsc/include/stlport/stl/_string.h:372: warning: inlining failed
> in call to ‘stlpmtx_std::basic_string<_CharT, _Traits,
> _Alloc>::~basic_string() [with _CharT = char, _Traits =
> stlpmtx_std::char_traits<char>, _Alloc =
> stlpmtx_std::allocator<char>]Â’: call is unlikely and code size would
> grow
> xmmmap.cc:2166: warning: called from here
> /work/smsc/include/stlport/stl/_string.h:372: warning: inlining failed
> in call to ‘stlpmtx_std::basic_string<_CharT, _Traits,
> _Alloc>::~basic_string() [with _CharT = char, _Traits =
> stlpmtx_std::char_traits<char>, _Alloc =
> stlpmtx_std::allocator<char>]Â’: call is unlikely and code size would
> grow
> xmmmap.cc:2168: warning: called from here
> /work/smsc/include/stlport/stl/_string.h:372: warning: inlining failed
> in call to ‘stlpmtx_std::basic_string<_CharT, _Traits,
> _Alloc>::~basic_string() [with _CharT = char, _Traits =
> stlpmtx_std::char_traits<char>, _Alloc =
> stlpmtx_std::allocator<char>]Â’: call is unlikely and code size would
> grow
> xmmmap.cc:2168: warning: called from here
> In file included from /work/smsc/include/stlport/stl/_string_io.h:23,
>
>                   from /work/smsc/include/xmmhdrmx.h:24,
>                   from xmmmanmx.cc:21:
> /work/smsc/include/xrslimmx.h:213: warning: padding struct to align
> ‘xrsIpSocketParameters_s::portNumber’
> In file included from /work/smsc/include/xsc_common_mx.h:25,
>                   from /work/smsc/include/xscalamx.h:31,
>                   from /work/smsc/include/xmmhdrmx.h:24,
>                   from xmmmanmx.cc:21:
> /work/smsc/include/xrsdefmx.h:54: warning: padding struct size to
> alignment boundary
> /work/smsc/include/xrsdefmx.h:59: warning: padding struct size to
> alignment boundary
> /work/smsc/include/xrsdefmx.h:89: warning: padding struct to align
> ‘<anonymous struct>::smUserData’
> /work/smsc/include/xrsdefmx.h:93: warning: padding struct to align
> ‘<anonymous struct>::tariffClass’
> /work/smsc/include/xrsdefmx.h:83: warning: padding struct size to
> alignment boundary
> /work/smsc/include/xrsdefmx.h:106: warning: padding struct to align
> ‘<anonymous struct>::msgRef’
> /work/smsc/include/xrsdefmx.h:114: warning: padding struct to align
> ‘<anonymous struct>::msgRef’
> /work/smsc/include/xrsdefmx.h:116: warning: padding struct to align
> ‘<anonymous struct>::destIMSIAddr’
> /work/smsc/include/xrsdefmx.h:118: warning: padding struct to align
> ‘<anonymous struct>::smUserData’
> /work/smsc/include/xrsdefmx.h:125: warning: padding struct to align
> ‘<anonymous struct>::msgRef’
> /work/smsc/include/xrsdefmx.h:127: warning: padding struct to align
> ‘<anonymous struct>::smUserData’
> /work/smsc/include/xrsdefmx.h:130: warning: padding struct to align
> ‘<anonymous struct>::origIMSIAddr’
> /work/smsc/include/xrsdefmx.h:137: warning: padding struct to align
> ‘<anonymous struct>::msgRef’
> /work/smsc/include/xrsdefmx.h:146: warning: padding struct to align
> ‘<anonymous struct>::msgRef’
> /work/smsc/include/xrsdefmx.h:162: warning: padding struct to align
> ‘<anonymous struct>::destIMSIAddr’
> /work/smsc/include/xrsdefmx.h:164: warning: padding struct to align
> ‘<anonymous struct>::smUserData’
> /work/smsc/include/xrsdefmx.h:172: warning: padding struct to align
> ‘<anonymous struct>::moSmLimit’
> /work/smsc/include/xrsdefmx.h:198: warning: padding struct size to
> alignment boundary
> /work/smsc/include/xrsdefmx.h:205: warning: padding struct to align
> ‘<anonymous struct>::imsiAddr’
> /work/smsc/include/xrsdefmx.h:203: warning: padding struct size to
> alignment boundary
> /work/smsc/include/xrsdefmx.h:212: warning: padding struct to align
> ‘<anonymous struct>::cause’
> /work/smsc/include/xrsdefmx.h:225: warning: padding struct size to
> alignment boundary
> /work/smsc/include/xrsdefmx.h:317: warning: padding struct to align ‘WPrim::req’
>
> thanks
> On Fri, Sep 16, 2011 at 2:31 PM, Ian Lance Taylor<iant@google.com>  wrote:
>> zou wonder<wonder.zou@gmail.com>  writes:
>>
>>> another is what is the difference between -O0 and -O?
>>
>> Please reply to the mailing list, not just to me.  Thanks.
>>
>> -O0 means no optimization.  -O, which is the same as -O1, means to
>> optimize the code.  This is explained in the manual.
>>
>>
>>> On Fri, Sep 16, 2011 at 2:16 PM, zou wonder<wonder.zou@gmail.com>  wrote:
>>>> Hi Ian:
>>>>
>>>>      Acctually, i intercept the codes from our product, and there are
>>>> tons of lines.
>>>>
>>>> so how can i provide that useful information?
>>
>> I don't know.  What I do know is that we can't help you without seeing
>> much more of the program.  The tiny bit of code you showed looked fine.
>> The problem was probably somewhere else.
>>
>> Ian
>>
>>
>>>> On Fri, Sep 16, 2011 at 1:40 PM, Ian Lance Taylor<iant@google.com>  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
>>>>>
>>>>
>>
>




More information about the Gcc-help mailing list