C 有哪些有用的 GCC 标志? [英] What are the useful GCC flags for C?
问题描述
除了设置 -Wall
和设置 -std=XXX
之外,还有哪些其他真正有用但鲜为人知的编译器标志可用于 C 中?
Beyond setting -Wall
, and setting -std=XXX
, what other really useful, but less known compiler flags are there for use in C?
我对任何其他警告和/或在某些情况下将警告转化为错误特别感兴趣,以绝对减少任何意外的类型不匹配.
I'm particularly interested in any additional warnings, and/or and turning warnings into errors in some cases to absolutely minimize any accidental type mismatches.
推荐答案
几个 -f
代码生成选项很有趣:
Several of the -f
code generation options are interesting:
-fverbose-asm
如果您使用-S
进行编译以检查程序集输出,则非常有用 - 它添加了一些信息性注释.
-fverbose-asm
is useful if you're compiling with-S
to examine the assembly output - it adds some informative comments.
-finstrument-functions
添加代码以在每个函数入口和出口点调用用户提供的分析函数.
-finstrument-functions
adds code to call user-supplied profiling functions at every function entry and exit point.
--coverage
检测程序中的分支和调用并创建覆盖注释文件,以便在程序运行时生成覆盖数据,该数据可以由 gcov
帮助分析测试覆盖率的程序.
--coverage
instruments the branches and calls in the program and creates a coverage notes file, so that when the program is run coverage data is produced that can be formatted by the gcov
program to help analysing test coverage.
-fsanitize={address,thread,undefined}
分别启用 AddressSanitizer、ThreadSanitizer 和 UndefinedBehaviorSanitizer 代码清理器.这些检测程序在运行时检查各种错误.
-fsanitize={address,thread,undefined}
enables the AddressSanitizer, ThreadSanitizer and UndefinedBehaviorSanitizer code sanitizers respectively. These instrument the program to check for various sorts of errors at runtime.
以前这个答案也提到了 -ftrapv
,但是这个功能已经被 -fsanitize=signed-integer-overflow
取代,它是 -fsanitize=undefined
.
Previously this answer also mentioned -ftrapv
, however this functionality has been superseded by -fsanitize=signed-integer-overflow
which is one of the sanitizers enabled by -fsanitize=undefined
.
这篇关于C 有哪些有用的 GCC 标志?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!