gpt4 book ai didi

c++ - Gcc 忽略 -Wno-unused-variable

转载 作者:行者123 更新时间:2023-11-28 06:41:51 29 4
gpt4 key购买 nike

我正在使用从 trunk 编译的 gcc version 4.8.3 20140624gcc4.9.1。但是,online compilers 上的标志似乎并未被忽略。 .这是测试程序:

#include <iostream>

int main()
{
int i;
}

和 shell 输出:

g++ -std=c++11 -O2 -Wall -Wextra -pedantic -Wno-unused-variable -I./ -c -o test.o test.cpp

test.cpp:6:5: warning: unused parameter ‘argc’ [-Wunused-parameter]
int main(int argc, char* argv[])
^
test.cpp:6:5: warning: unused parameter ‘argv’ [-Wunused-parameter]

最佳答案

用下面的程序

int main(int argc, char** argv)
{
int i;
}

使用 g++ -std=c++11 -O2 -Wall -Wextra -pedantic -Wno-unused-variable
您没有未使用变量 i 的警告。
如果您不想对参数 argcargv
发出警告还添加编译器标志 -Wno-unused-parameter

Live example

关于c++ - Gcc 忽略 -Wno-unused-variable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25835070/

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