[An Introduction to GCC 学习笔记] 09 -Wall

Warning Options in -Wall

The warning option ‘-Wall’ enables warning for many common errors, and should always be used. It combines a large number of other, more specific, warning options which can also be selected individually:

  • ‘-Wcomment’
  • ‘-Wformat’
  • ‘-Wunused’
  • ‘-Wimplicit’
  • ‘-Wreturn-type’

-Wcomment

  • This option warns about nested comments. Nested comments typically arise when a section of code containing comments is later commented out.
  • Nested comments can be a source of confusion = the safe way to “comment out” a section of code containing comments is to surround it with the preprocessor directive
  • #if 0 … #end if

-Wformat

  • This option warns about the incorrect use of format strings in functions such as printf and scanf, where the format specifier does not agree with the type of the corresponding function argument.

-Wunused

  • This option warns about unused variables. When a variable is declared but not used this can be the result of another variable being accidentally substituted in its place. If the variable is genuinely not needed it can be removed from the source code.

-Wimplicit

  • This option warns about any functions that are used without being declared. The most common reason for a function to be used without being declared is forgetting to include a head file.

-Wreturn-type

  • This option warns about functions that are defined without a return type but not declared void. It also catches empty return statements in functions that are not declared void.

补充

  • The complete set of warning options included in ‘-Wall’ can be found in the GCC Reference Manual “Using GCC”.
  • The options included in ‘-Wall’ have the common characteristic that they report constructions which are always wrong, or can easily be rewritten in an unambiguously correct way. This is why they are so useful - any warning produced by ‘-Wall’ can be taken as an indication of a potentially serious problem.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值