为什么`得到()`是德precated? [英] Why `gets()` is deprecated?

查看:230
本文介绍了为什么`得到()`是德precated?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用获得()在我的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 shouts

warning: 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 of C standard [C11 onwards]. So, C libraries compilers are 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 of gets(), the compiler## emits the warning message.


(##) To be pedantic, the warning is not generated by the compiler (gcc) all by itself, rather caused by a pragma or attribute on the implementation of gets() in the glibc that causes the compiler to emit the warning. [Courtesy, FUZxxl, from the dupe answer.]

这篇关于为什么`得到()`是德precated?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆