gpt4 book ai didi

c - 为什么 -Winit-self 与 -Wuninitialized 分开

转载 作者:太空狗 更新时间:2023-10-29 15:38:34 27 4
gpt4 key购买 nike

This Question是关于让 gcc 编译器在您输入错误时发出警告并用自身初始化变量。

      int f()
{
int i = i;
return i;
}

原来你需要 -Winit-self flag除了-Wuninitialized:

-Winit-self (C, C++, Objective-C and Objective-C++ only) Warn about uninitialized variables which are initialized with themselves. Note this option can only be used with the -Wuninitialized option, which in turn only works with -O1 and above.

我的问题是:为什么这不是 -Wuninitialized 的默认行为?在什么用例中,您想警告未初始化的变量,而不是自初始化的变量,它们同样麻烦?

最佳答案

看起来像这个错误报告Warn about member variables initialized with itself对此有解释(强调我的):

I agree with Andrew, the a(a) mistake should always warn, it should be independent of -Winit-self, which exists so that -Wuninitialized doesn't warn about the common (but questionable) practice of self-initializing automatic variables to silence warnings.

它可能被称为有问题的做法,因为它是 undefined behavior in C++ to self initialize an automatic variable错误报告是 C++ 错误报告。

关于c - 为什么 -Winit-self 与 -Wuninitialized 分开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22965414/

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