为什么“得到”尚未弃用? [英] Why "gets" has not been deprecated yet?

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

问题描述

我们都知道得到标准C库中的函数(

是标准C ++库的一部分)是危险的。它没有提供

边界检查,因此在使用它时很容易覆盖内存,并且

无法保证它不会发生。


因此,我认为令人惊讶的是,这个功能还没有被弃用。

C ++ 98标准保留了它来自C89标准。

C99标准保留了它:-o。


现在,C标准委员会正致力于安全功能(这些<对于C标准库,以_s结尾的
。我不知道他们是否会贬低可怕的获取。即使不是,我认为在下一个C ++标准中弃用它是个好主意,因为

C ++有更好的方法来完成相同的任务(getline) 。期待C ++标准中的安全功能(* _s)早期太多了
,但

摆脱获取不是那么难,不是吗?无论如何,使用它的程序

都会被破坏。此外,C ++已经弃用了C中的其他功能,因为C ++有更好的选择(静态意义是内部链接

和标题以.h结尾)。


意见?这条消息应该发布在comp.std.c ++上吗?

We all know that the "gets" function from the Standard C Library (which
is part of the Standard C++ Library) is dangerous. It provides no
bounds check, so it''s easy to overwrite memory when using it, and
impossible to guarantee that it won''t happen.

Therefore, i think it''s surprising that this function has not been
deprecated.
The C++98 Standard keeps it from the C89 standard.
The C99 Standard has kept it :-o.

Now, the C standard committee is working on safe functions (the ones
that end with "_s") for the C Standard Library. I don''t know if they
are going to deprecate the dreaded "gets". Even if not, i think it
would be a good idea to deprecate it in the next C++ standard, since
C++ has better ways to accomplish the same task (getline). It''s too
early to expect the safe functions (*_s) in the C++ Standard, but
getting rid of "gets" is not that hard, isn''t it? Programs that use it
are broken anyway. Also, C++ has deprecated other features from C just
because C++ has better alternatives (static meaning "internal linkage"
and headers ending in ".h").

Opinions? Should this message be posted on comp.std.c++?

推荐答案

Marcus写道:
意见?这条消息应该发布在comp.std.c ++上吗?
Opinions? Should this message be posted on comp.std.c++?




你可能想把它发布在那里,因为这里的人一般

更多地关注应用,而不是更改/辩论

标准。


小心假设所有使用获取的东西都是
$然而b $ b仍然存在缺陷。 = <



You probably want to post it over there, as people on here generally
focus more on application, and less on changing / debating the
standard.

Be careful with the assumption that all things using gets are
inherantly flawed however. =P


Josh Mcfarlane写道:
Josh Mcfarlane wrote:
小心假设所有使用gets的东西都是
Be careful with the assumption that all things using gets are
inherantly flawed however. =P




好​​吧,得到调用未定义的行为。



Well, gets invokes undefined behavior.


Rolf Magnus写道:
Rolf Magnus wrote:
好吧,gets会调用未定义的行为。
来自缓冲区溢出?如果没有,还有什么导致未定义的行为?
Well, gets invokes undefined behavior. From a buffer overrun? If not, what else causes the undefined behavior?






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

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