gpt4 book ai didi

gcc - 条件功能的警告开关作为变量

转载 作者:行者123 更新时间:2023-12-01 16:18:35 24 4
gpt4 key购买 nike

我错误地忘记了在函数调用之后放置参数列表,并且 gcc 没有拦截(因为他认为这是一个 TRUTH-value)。是否有 gcc 警告/错误开关,可以帮助我找到那些地方?示例:

short function(short arg);

main() {
if (function) { // I wanted to write function(arg)
//do something
}
}

我使用的gcc版本是3.2.1。

最佳答案

看GCC man page,好像你需要的是-Waddress

   -Waddress
Warn about suspicious uses of memory addresses. These include using the address of a function in a conditional
expression, such as "void func(void); if (func)", and comparisons against the memory address of a string literal, such as
"if (x == "abc")". Such uses typically indicate a programmer error: the address of a function always evaluates to true,
so their use in a conditional usually indicate that the programmer forgot the parentheses in a function call; and
comparisons against string literals result in unspecified behavior and are not portable in C, so they usually indicate
that the programmer intended to use "strcmp". This warning is enabled by -Wall.

如那里所述,您也可以使用 -Wall 启用此标志。

关于gcc - 条件功能的警告开关作为变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25522987/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com