如何使g++引起异常而不是对格式错误发出警告
how to make g++ cause an exception instead of warning on format mistake
我需要强制gcc在这段代码上引发异常而不是警告:
#include <stdio.h>
int main()
{
printf ("Decimals: %d n", 1977123124L);
return 0;
}
现在当我运行cmd:
g++ test.cpp -o test.o
test.cpp是一个包含以下代码的文件。
我在输出中发出警告消息:
test.cpp:6: warning: format ‘%d’ expects type ‘int’, but argument 2 has type ‘long int’
和测试。
我想要的是错误信息和编译失败。
是否有一些标志或其他帮助gcc为我做这件事?
谢谢=)
使用交换机-Werror=format
一般来说,当你有一个警告,你想把它变成错误,使用-Werror=(warning name)
;在极端情况下,-Werror
单独作用会使所有警告变为错误。
相关文章:
- 如何将strftime中的格式错误作为异常捕获
- CuDNN 减少格式错误
- 漂亮的计数器习语的错误或格式错误的静态订单惨败?
- GCC 编译器是否应该对涉及 [[fallthrough]] 属性的格式错误的C++代码进行诊断?
- 在.NET Core 3.1中运行托管C++/CLI程序集时,映像格式错误
- -bash:/a.out:无法执行二进制文件:Exec格式错误
- 如何避免浮点格式错误
- 'fopen'返回格式错误的'fp'
- bash:./main:无法执行二进制文件:Exec格式错误
- 包含格式错误的模板成员函数的格式正确的程序?
- CPPRestSDK(casablanca)从传入的WebSocket消息中提取JSON(格式错误的令牌)
- 未定义的行为和格式错误之间的区别,不需要诊断消息
- C++计算中的格式错误
- C++输出格式错误
- 未知像素格式错误SDL2
- 常量的预处理器宏-格式错误
- BeautifulSoup的C / CPP版本,特别是在处理格式错误的HTML方面
- 格式错误的隐式转换示例
- bash:即使二进制和Linux是64位的,也无法执行二进制文件:Exec格式错误
- 升级后出现libcurl格式错误的url错误(CURLE_url_MALFORMAT)