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

Posted 漫小牛

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[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.

以上是关于[An Introduction to GCC 学习笔记] 09 -Wall的主要内容,如果未能解决你的问题,请参考以下文章

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

[An Introduction to GCC 学习笔记] 14 优化问题3

[An Introduction to GCC 学习笔记] 14 优化问题3

[An Introduction to GCC 学习笔记] 13 优化问题2

[An Introduction to GCC 学习笔记] 10 Warn预编译

[An Introduction to GCC 学习笔记] 07 链接外部静态库