Mail Archives: djgpp/1997/12/04/20:44:00
Nate Eldredge wrote:
>
> At 07:37 12/4/1997 -0500, Peter Palotas wrote:
> >>make a habit of setting fp to NULL after closing it. AFAIK, files do not
> >>close themselves.
> >
> >I actually think that the libc exit code does this for you, although it is
> >probably not defined in the ANSI standard that the files should be closed,
> >but DJGPP does this, I think.
> DJGPP quite definitely does it. I expect that it is part of the ANSI
> standard, since automatically closing files is guaranteed as far back
> as K&R I. Of course, it is best to close a file when you finish with
>it.
of course all files are closed upon program termination. that is the
required ansi behavior. the original poster was talking about not
knowing whether a given FILE* fp pointed to was open or not. there is no
way to portably do that. however, since the programmer has to take an
action to close the file, he/she can also set the pointer to NULL so
subsequent users of the pointer can check that to see if it was closed.
--
----------------------------------------------------------------------
A. Sinan Unur
Department of Policy Analysis and Management, College of Human Ecology,
Cornell University, Ithaca, NY 14853, USA
mailto:sinan DOT unur AT cornell DOT edu
http://www.people.cornell.edu/pages/asu1/
- Raw text -