测试fclose ......真的很有必要 [英] testing fclose...really necessary

查看:100
本文介绍了测试fclose ......真的很有必要的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否真的有必要检查返回类型(int)还是fclose? fopen

我能理解但是使用


fflsuh(fp); / * fopen'的指针* /

fclose(fp);


是否可以解决任何不可预见的截断问题?

Bill

解决方案



" Bill Cunningham" < no **** @ nspam.comwrote in message


是否真的有必要检查返回类型(int)还是fclose? fopen

我能理解但是使用


fflsuh(fp); / * fopen'的指针* /

fclose(fp);


是否会处理任何不可预见的截断?


如果程序没有成功关闭文件,这意味着计算机出现了严重错误的问题。就像磁盘已满,或者

设备驱动程序崩溃了。至少FILE *你传递给

函数moght已经损坏。

重要的是告诉用户,如果数据很重要,那么有什么

发生了。

但是很多程序都没有保存重要数据。然后它可以说是一个

可接受的懒惰,不检查fclose()。该程序不太可能在没有不可接受的额外

编程水平的情况下做任何事情,并且错误是非常罕见的。

fflush()必须被检查而不是fclose(),所以你不是真的

用你建议的策略保存任何东西。


-

免费游戏和编程好东西。
http://www.personal.leeds.ac.uk/~bgy1mm


8月8日,4:58 * pm, 比尔坎宁安 < nos ... @ nspam.comwrote:


* *是否真的有必要检查返回类型(int)或fclose?fopen

我能理解但是使用


fflsuh(fp); / * fopen'的指针* /

fclose(fp);


是否可以解决任何不可预见的截断问题?

比尔



埃里克索斯曼发布了一个令人信服的例子,说明什么时候出现问题

不检查回报fclose()的价值一段时间后,您可以在< http://groups.google.com/group/comp.lang.c/msg/c601c3fd60dd536a>上阅读它




-

Robert Gamble


Robert Gamble写道:


8月8日下午4:58,Bill Cunningham < nos ... @ nspam.comwrote:


>是否真的有必要检查返回类型(int)还是fclose? fopen
我能理解但是使用

fflsuh(fp); / * fopen'的指针* /
fclose(fp);

是否会处理任何不可预见的截断?

Bill



Eric Sosman发布了一个令人信服的例子,说明你什么时候会出错?

一段时间后不检查fclose()的返回值,你可以阅读它是< http://groups.google.com/group/comp.lang.c/msg/c601c3fd60dd536a>的



Gad,这是一次糟糕的体验!我最后飞到圣路易斯

试图安抚愤怒的客户,让他用奶酪刨丝器扯下我的脸

- 好吧,也许我夸大了,但我的一天在

圣路易斯留在记忆中是我工作中最不愉快的生活之一。


错误检查的彻底性应该取决于数据的重要性,而不是程序员的便利性。


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


Is it really necessary to check the return type (int) or fclose ? fopen
I can understand but what about using

fflsuh(fp); /* fopen''s pointer */
fclose(fp);

Would that take care of any unforseen truncation ?

Bill

解决方案


"Bill Cunningham" <no****@nspam.comwrote in message

Is it really necessary to check the return type (int) or fclose ? fopen
I can understand but what about using

fflsuh(fp); /* fopen''s pointer */
fclose(fp);

Would that take care of any unforseen truncation ?

If the program won''t close a file successfully that means that something is
seriously wrong with the computer. Like the disk being full up, or the
device driver corruupted. At the very least the FILE * you pass to the
function moght have been corrupted.
The important thing is to tell the user, if the data is important, what has
happened.
However a lot of programs don''t save important data. Then it is arguably an
acceptable laziness not to check fclose(). The program is unlikely to be
able to do anything about it without an unacceptable level of extra
programming, and errors are very rare.
fflush() would have to be checked instead of fclose(), so you don''t really
save anything with your suggested strategy.

--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm


On Aug 8, 4:58*pm, "Bill Cunningham" <nos...@nspam.comwrote:

* * Is it really necessary to check the return type (int) or fclose ?fopen
I can understand but what about using

fflsuh(fp); /* fopen''s pointer */
fclose(fp);

Would that take care of any unforseen truncation ?

Bill

Eric Sosman posted a compelling example of what can go wrong when you
don''t check the return value of fclose() a while back, you can read it
at <http://groups.google.com/group/comp.lang.c/msg/c601c3fd60dd536a>.

--
Robert Gamble


Robert Gamble wrote:

On Aug 8, 4:58 pm, "Bill Cunningham" <nos...@nspam.comwrote:

> Is it really necessary to check the return type (int) or fclose ? fopen
I can understand but what about using

fflsuh(fp); /* fopen''s pointer */
fclose(fp);

Would that take care of any unforseen truncation ?

Bill


Eric Sosman posted a compelling example of what can go wrong when you
don''t check the return value of fclose() a while back, you can read it
at <http://groups.google.com/group/comp.lang.c/msg/c601c3fd60dd536a>.

Gad, that was an awful experience! I wound up flying to St. Louis
to try to placate the irate customer by allowing him to rip my face
off with a cheese grater -- well, perhaps I exaggerate, but my day in
St. Louis remains in memory as one of the most unpleasant of my working
life.

The thoroughness of the error-checking should be a function of the
importance of the data, not of the programmer''s ideas of convenience.

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


这篇关于测试fclose ......真的很有必要的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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