scanf函数声明 [英] Scanf statement
问题描述
的#include<&stdio.h中GT;
#包括LT&;&stdlib.h中GT;
您好,我想知道为什么这个系统并不执行程序。它好像我一直具有正常履行scanf函数功能的麻烦。我得到的错误:
错误:与属性warn_unused_result声明scanf函数的忽略返回值
请注意:我知道有写我目前的方案更有效的方法,但这是题外话。我想知道这是什么错误意味着,为什么我不断收到它,可能的解决方案。感谢你们。这里是code:
INT主(INT ARGC,CHAR *的argv []){ INT X;
诠释Ÿ;
INT Z者除外;
INT温度; scanf函数(%d个,&安培; X);
scanf函数(%d个,&安培; Y);
scanf函数(%d个,&安培; Z); 如果(X> Y){
TEMP = X;
X = Y;
Y =温度;
} 如果(Y> Z){
温度= Y;
Y = Z;
Z =温度;
} 如果(X将Z){
TEMP = X;
X = Z者除外;
Z =温度;
} 的printf(%D,X);
的printf(%D,Y);
的printf(%D,Z); 返回EXIT_SUCCESS; }
从GCC文档:
的
warn_unused_result
属性会导致发出警告
如果函数与此属性的调用者不利用其
返回值。这是地方为函数不检查有用
结果要么是一个安全问题,或者总是一个bug,如
的realloc
。INT FN()__attribute__((warn_unused_result));
INT富()
{
如果(FN()℃,)返回-1;
FN();
返回0;
}在警告结果第5行。
块引用>#include <stdio.h> #include <stdlib.h>
Hello, I was wondering why this program doesn't execute. It seems as though I've always been having trouble with performing the scanf function properly. I get the error of:
error: ignoring return value of scanf declared with attribute warn_unused_result
Note: I know there is a more efficient method for writing my current program, but that is beside the point. I want to know what this error means and why I keep getting it and possibly a solution. Thank you guys. Here is the code:
int main (int argc, char *argv[]){ int x; int y; int z; int temp; scanf("%d", &x); scanf("%d", &y); scanf("%d", &z); if (x > y) { temp = x; x = y; y = temp; } if (y > z) { temp = y; y = z; z = temp; } if (x > z) { temp = x; x = z; z = temp; } printf("%d", x); printf("%d", y); printf("%d", z); return EXIT_SUCCESS; }
解决方案From the GCC documentation:
The
warn_unused_result
attribute causes a warning to be emitted if a caller of the function with this attribute does not use its return value. This is useful for functions where not checking the result is either a security problem or always a bug, such asrealloc
.int fn () __attribute__ ((warn_unused_result)); int foo () { if (fn () < 0) return -1; fn (); return 0; }
results in warning on line 5.
这篇关于scanf函数声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!