c++ - why does fclose not set file pointer to NULL? -
I was writing an RAI wrapper for FILE *. I have seen that when the file is destroyed after being deleted * it leads to undefined behavior (sig mistake or errors somewhere else). I think the fclose file will be set * null *, which did not do it. Of course Setting
delete fp is causing an accident. It was not allocated with
new . Call only
Delete with something you've got a
new or you have been asked to use it with some other documents. The document for
fopen will never allow you to
delete all the cleaning
fclose ; You do not need to do anything after releasing file-related resources.
fp = NULL OK This is probably desirable so that the future consumer "Smart File Notifier" can check whether the indicator is still valid or not. (This is more useful than the method from a
reset to the destroyer, though; after the execution of the pest, the indicator class can not have any future users because the objects are no longer present.) But < Code> fclose can not do this because because
fclose does not get its parameters based on context, and even if it does, then it everyone Will not be able to cancel the possibility of file indicator Remember Ian that
free and
Delete are set to
NULL to their argument,
Comments
Post a Comment