gcc 关于隐式初始化的选项说明

2 篇文章 0 订阅
1 篇文章 0 订阅
       -Wmaybe-uninitialized
           For an automatic variable, if there exists a path from the function
           entry to a use of the variable that is initialized, but there exist
           some other paths the variable is not initialized, the compiler will
           emit a warning if it can not prove the uninitialized paths do not
           happen at run time. These warnings are made optional because GCC is
           not smart enough to see all the reasons why the code might be
           correct despite appearing to have an error
难过.  Here is one example of
           how this can happen:

                   {
                     int x;
                     switch (y)
                       {
                       case 1: x = 1;
                         break;
                       case 2: x = 4;
                         break;
                       case 3: x = 5;
                       }
                     foo (x);
                   }

           If the value of "y" is always 1, 2 or 3, then "x" is always
           initialized, but GCC doesn't know this. To suppress the warning,
           the user needs to provide a default case with assert(0) or similar
           code.

           This option also warns when a non-volatile automatic variable might
           be changed by a call to "longjmp".  These warnings as well are
           possible only in optimizing compilation.

           The compiler sees only the calls to "setjmp".  It cannot know where
           "longjmp" will be called; in fact, a signal handler could call it
           at any point in the code.  As a result, you may get a warning even
           when there is in fact no problem because "longjmp" cannot in fact
           be called at the place that would cause a problem.

           Some spurious warnings can be avoided if you declare all the
           functions you use that never return as "noreturn".

           This warning is enabled by -Wall or -Wextra.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值