为什么`得到()`是德precated? [英] Why `gets()` is deprecated?
问题描述
在使用获得()
在我的code,编译器喊声
警告:'得到'功能是危险的,不应该used.`
和
警告:'得到'是去precated(在/usr/include/stdio.h:638声明)
[-Wde precated-声明]
任何特殊的理由?
的有人可以解释为什么编译器显示这样的...?的
块引用>是的,因为,在
获得()
函数是危险的,因为它从缓冲区溢出问题受到影响。任何人都应该避免使用的。此外,关于与
-Wde precated-声明)警告
,获取(
不再的C部分
标准[C11
起。因此,C库编译没有的约束的以支持更多。它可以在将来被移除。要提醒开发商对潜在的缺陷,并劝阻进一步得到使用()
,编译 ## 发出警告消息。(##)要学究,不是由编译器生成的警告(
GCC
)所有的本身,而是由一个引起编译
或得到()
在的glibc
的原因编译器发出警告。 [礼貌,FUZxxl,从欺骗答案]While using
gets()
in my code, the compiler shoutswarning: the 'gets' function is dangerous and should not be used.`
and
warning: ‘gets’ is deprecated (declared at /usr/include/stdio.h:638) [-Wdeprecated-declarations]
Any specific reasons?
解决方案Can someone explains why the compiler shows like that…?
Yes, because, the
gets()
function is dangerous, as it suffers from buffer overflow issue. Anyone should refrain from using that.Also, regarding the warning with
-Wdeprecated-declarations
,gets()
is no longer a part ofC
standard [C11
onwards]. So, C librariescompilersare not bound to support that any more. It can be removed in future. To warn the developer about the potential pitfall and to discourage the further usage ofgets()
, the compiler## emits the warning message.
(##) To be pedantic, the warning is not generated by the compiler (
gcc
) all by itself, rather caused by apragma
or attribute on the implementation ofgets()
in theglibc
that causes the compiler to emit the warning. [Courtesy, FUZxxl, from the dupe answer.]这篇关于为什么`得到()`是德precated?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!