得到()理由 [英] gets() rationale

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

问题描述

获得()被普遍承认是破碎和无用的;但是,

它仍然是标准库的一部分。为什么?是否有足够的

符合代码使用gets()来证明保留它?

计划在未来版本中弃用或消除它吗?


-

Christopher Benson-Manica |我*应该*知道我在说什么 - 如果我

ataru(at)cyberspace.org |不,我需要知道。火焰欢迎。

gets() is universally acknowledged to be broken and useless; however,
it is still part of the standard library. Why? Is there enough
conforming code out there using gets() to justify retaining it? Are
there plans to deprecate or eliminate it in a future version?

--
Christopher Benson-Manica | I *should* know what I''m talking about - if I
ataru(at)cyberspace.org | don''t, I need to know. Flames welcome.

推荐答案

Christopher Benson-Manica写道:
Christopher Benson-Manica wrote:

gets()被公认为是破碎无用;但是,它仍然是标准库的一部分。为什么?是否有足够的
符合代码使用gets()来证明保留它?是否有计划在未来的版本中弃用或消除它?

gets() is universally acknowledged to be broken and useless; however,
it is still part of the standard library. Why? Is there enough
conforming code out there using gets() to justify retaining it? Are
there plans to deprecate or eliminate it in a future version?




comp.std.c的问题,methinks。后续行动确定。


据猜测,委员会并不觉得有可能自由地进行改革。传统的C库,即使事后看来

显示其部分功能可以更好地设计。

< varargs.h>我认为,这只是唯一的减法,而不是
,原因是它的传统形式非常可靠,但在某些感兴趣的机器上无法实现。


-
Er ********* @ sun.com


2003-12-02,Christopher Benson-Manica< at *** @ nospam.cyberspace.org>写道:
On 2003-12-02, Christopher Benson-Manica <at***@nospam.cyberspace.org> wrote:
gets()被普遍认为是破碎和无用的;但是,它仍然是标准库的一部分。为什么?是否有足够的
符合代码使用gets()来证明保留它?是否有计划在将来的版本中弃用或消除它?
gets() is universally acknowledged to be broken and useless; however,
it is still part of the standard library. Why? Is there enough
conforming code out there using gets() to justify retaining it? Are
there plans to deprecate or eliminate it in a future version?




AC编译器可以在已知的函数生成诊断时
$ b使用$ b是不安全的,建议使用更安全的替代方案。 (我好像记得在BSD版本的gcc上看到这样的警告。)


- James



A C compiler could generate a diagnostic when functions that are known
to be unsafe are used and suggest a safer alternative instead. (I seem
to remember seeing such warnings on the BSD version of gcc.)

-- James

Christopher Benson-Manica< at *** @ nospam.cyberspace.org>写道:
Christopher Benson-Manica <at***@nospam.cyberspace.org> writes:
gets()被普遍认为是破碎和无用的;但是,它仍然是标准库的一部分。为什么?是否有足够的
符合代码使用gets()来证明保留它?是否有计划在未来的版本中弃用或消除它?
gets() is universally acknowledged to be broken and useless; however,
it is still part of the standard library. Why? Is there enough
conforming code out there using gets() to justify retaining it? Are
there plans to deprecate or eliminate it in a future version?




以下是C99的理由说明:


30 7.19.7.7获取功能


因为获取不检查缓冲区溢出,所以当它的输入不是时,它通常是不安全的在
程序员的控制之下。这导致一些人质疑

是否应该出现在标准中。

35委员会认为,当程序员确实对输入有足够的控制权时,这些特殊情况下的获取是有用和方便的。长期以来,它需要一个标准的规范。然而,在

一般情况下,首选函数是fgets(参见

?§7.19.7.2)。


-

char a [] =" \ n .CJacehknorstu" ;; int putchar(int); int main(void){unsigned long b []

= {0x67dffdff, 0x9aa9aa6a,0xa77ffda9,0x7da6aa6a,0xa6 7f6aaa,0xaa9aa9f6,0x1f6},* p =

b,x,i = 24; for(; p + =!* p; * p / = 4)switch(x = * p& 3)case 0:{return 0; for(p - ; i - ; i - )case

2:{i ++; if(1)break; else default:继续;如果(0)案例1:putchar(a [i& 15]); break;}}}



Here is what the C99 rationale says:

30 7.19.7.7 The gets function

Because gets does not check for buffer overrun, it is
generally unsafe to use when its input is not under the
programmer''s control. This has caused some to question
whether it should appear in the Standard at all. The
35 Committee decided that gets was useful and convenient in
those special circumstances when the programmer does have
adequate control over the input, and as longstanding
existing practice, it needed a standard specification. In
general, however, the preferred function is fgets (see
?§7.19.7.2).

--
char a[]="\n .CJacehknorstu";int putchar(int);int main(void){unsigned long b[]
={0x67dffdff,0x9aa9aa6a,0xa77ffda9,0x7da6aa6a,0xa6 7f6aaa,0xaa9aa9f6,0x1f6},*p=
b,x,i=24;for(;p+=!*p;*p/=4)switch(x=*p&3)case 0:{return 0;for(p--;i--;i--)case
2:{i++;if(1)break;else default:continue;if(0)case 1:putchar(a[i&15]);break;}}}


这篇关于得到()理由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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