delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/12/04/20:44:00

Message-ID: <34875C7D.C9FAD485@cornell.edu>
Date: Thu, 04 Dec 1997 20:44:29 -0500
From: "A. Sinan Unur" <sinan DOT unur AT cornell DOT edu>
Organization: Cornell University (http://www.cornell.edu/)
MIME-Version: 1.0
To: Nate Eldredge <eldredge AT ap DOT net>
CC: djgpp AT delorie DOT com
Subject: Re: Simple beginner questions
References: <199712050124 DOT RAA26244 AT adit DOT ap DOT net>

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019