c - 哪些选项与 gcc 一起使用以获得最大的安全检查?

标签 c visual-c++ gcc

我在工作中使用 VC++ 2010,在家使用 gcc 4.7 进行 C、C++ 编程。我注意到用于检查细微错误(如堆栈溢出、堆损坏、使用未初始化变量等)的编译器选项在 vc++ 中默认启用,但在 gcc 中不启用。在阅读 gcc 手册时,我发现了诸如“-fstack-protector”之类的选项来检查堆栈溢出/损坏。 我能否得到所有这些选项的列表和一些提示,以便像在 vc++ 中一样从 gcc 获得所有帮助? 谢谢。

最佳答案

您肯定在寻找Options to Request or Suppress Warnings

从网站上列出其中的一些:-

-fmax-errors=n

Limits the maximum number of error messages to n, at which point GCC bails out rather than attempting to continue processing the source code. If n is 0 (the default), there is no limit on the number of error messages produced. If -Wfatal-errors is also specified, then -Wfatal-errors takes precedence over this option.

-Wall

This enables all the warnings about constructions that some users consider questionable, and that are easy to avoid (or modify to prevent the warning), even in conjunction with macros. This also enables some language-specific warnings described in C++ Dialect Options and Objective-C and Objective-C++ Dialect Options. -Wall turns on the following warning flags:

      -Waddress   
      -Warray-bounds (only with -O2)  
      -Wc++11-compat  
      -Wchar-subscripts  
      -Wenum-compare (in C/ObjC; this is on by default in C++) 
      -Wimplicit-int (C and Objective-C only) 
      -Wimplicit-function-declaration (C and Objective-C only) 
      -Wcomment  
      -Wformat   
      -Wmain (only for C/ObjC and unless -ffreestanding)  
      -Wmaybe-uninitialized 
      -Wmissing-braces (only for C/ObjC) 
      -Wnonnull  
      -Wparentheses  
      -Wpointer-sign  
      -Wreorder   
      -Wreturn-type  
      -Wsequence-point  
      -Wsign-compare (only in C++)  
      -Wstrict-aliasing  
      -Wstrict-overflow=1  
      -Wswitch  
      -Wtrigraphs  
      -Wuninitialized  
      -Wunknown-pragmas  
      -Wunused-function  
      -Wunused-label     
      -Wunused-value     
      -Wunused-variable  
      -Wvolatile-register-var 
       Note that some warning flags are not implied by -Wall. Some of them warn about constructions that users generally do not consider

questionable, but which occasionally you might wish to check for; others warn about constructions that are necessary or hard to avoid in some cases, and there is no simple way to modify the code to suppress the warning. Some of them are enabled by -Wextra but many of them must be enabled individually.

关于c - 哪些选项与 gcc 一起使用以获得最大的安全检查?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19342630/

相关文章:

c++ - 不存在从 “cv::Mat”到 “IplImage”的合适的用户定义转换

c++ - 何时为可执行文件分配内核版本

c++ - 使用 void_t 和 protected 嵌套类进行基于 SFINAE 的检测

c - 读取文件失败

c - 为什么int16+int16比int16+int8快?

c - 在 C 语言中 - 计算 1 的序列

c - 从左到右、从上到下翻转图像

c++ - boost::asio async_send 错误

c++ - 适用于 Vista/Windows 7 的凭证管理器

c++ - 我在哪里可以找到 GCC 源代码中 strncpy() 函数的实现?