为什么get()被弃用? [英] Why gets() is deprecated?

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

问题描述

在我的代码中使用 gets()时,编译器大喊

While using gets() in my code, the compiler shouts

warning: the 'gets' function is dangerous and should not be used.`

warning: ‘gets’ is deprecated (declared at /usr/include/stdio.h:638)
[-Wdeprecated-declarations]

任何具体原因?

推荐答案


有人可以解释为什么编译器会这样显示......?

是的,因为, gets()函数是危险的,因为它会遇到缓冲区溢出问题。任何人都应该避免使用它。

Yes, because, the gets() function is dangerous, as it suffers from buffer overflow issue. Anyone should refrain from using that.

此外,关于 -Wdeprecated-declarations 的警告, gets()不再是 C 标准[ C11 之后]的一部分。因此,C库编译器不是绑定以支持它。它将来可以删除。为了警告开发人员潜在的陷阱并阻止进一步使用 gets(),编译器 ## 会发出警告消息。

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.

(##)要迂腐,编译器不会生成警告( gcc )本身,而不是由 pragma 的实现属性引起的get() glibc 中导致编译器发出警告。 [礼貌,FUZxxl,来自重复答案。]

(##) 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.]

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

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