我在ac程序中使用scanf从STDIN读取一个int:
scanf("%d", &n);
Run Code Online (Sandbox Code Playgroud)
当我编译启用优化的c程序时,我收到一些警告:
gcc main.c -lm -lpthread -O2 -o main
main.c: In function ‘main’:
main.c:45: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result
main.c:50: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result
Run Code Online (Sandbox Code Playgroud)
但是当我删除优化选项时,为什么不收到这些警告?
gcc main.c -lm -lpthread -o main
Run Code Online (Sandbox Code Playgroud)
PS:我没有使用-Wall或类似的东西.
Mat*_*Mat 11
更改优化程序设置会更改编译器分析代码的程度(以及如何).
未启用优化(或未设置足够高)时,不会执行某些程序流分析,因此不会发出相关警告.
您会经常看到"未使用的变量"警告 - 这些需要分析超出简单编译代码所需的代码,因此您通常只会在启用优化的情况下获取它们.
(你真的应该编译-Wall
.)
归档时间: |
|
查看次数: |
776 次 |
最近记录: |