【发布时间】:2011-11-17 10:20:32
【问题描述】:
基于 C++11 的 most recent draft,C++ 参考 ISO/IEC 9899:1999/Cor.3:2007(E) 对 C 库函数的定义(根据 §1.2[intro.refs] /1)。
基于 C99 TC3 的 most recent draft,The gets function is obsolescent, and is deprecated.(根据 §7.26.9/2)
我可以肯定地说gets() 在 C 和 C++ 中都已被弃用吗?
【问题讨论】:
-
这有关系吗?无论如何你都不应该使用它。
-
好吧,手册页上写着:
Never use gets(). Because it is impossible to tell without knowing the data in advance how many charac‐ters gets() will read, and because gets() will continue to store characters past the end of the buffer, it is extremely dangerous to use. It has been used to break computer security. Use fgets() Instead.所以,我想说不管它的官方状态如何,都不要使用它。 -
gets() 应该只用于教新程序员有关缓冲区溢出的知识。
-
我不使用它,但在争论中“危险”听起来不像“弃用”那么强烈。很多事情都是危险的。
-
@Cubbi:许多被错误标记为“危险”的东西都有正确和错误用途,称其为“危险”的人是根据某人以不正确的方式使用它的可能性强加自己的判断.另一方面,
gets基本上没有正确的用途;任何使用它都会导致程序出错。
标签: c++ c deprecated gets