Well, keep in mind that "close" is an extention, abet a very common one.
There are actually several places where the implementation choose to close
a file. The first could be the procedure or function to which the file is local.
Ie., if the file is permanently leaving scope, there is no reason not to close it.
The second would be when the program exits, that is, the support library for
the implementation can close the file.
Lastly, as discussed, the OS can close the file(s) as part of the shutdown for
the task/process.
For example, IP Pascal keeps a table of open files in the support library, and
shuts them down automatically when the program exits as part of a general
cleanup. It does not bother to try to close the files when they leave scope, which
would involve things like trying to find and close arrays or structures containing
files. Thus, the principle use of the "close" statement is to prevent the files table
from overflowing if you open too many files without closing them out. The
file table limit is 100 total open files, which would be easy to exceed if you were
to open a long list of files without closing them.
Scott Moore
-------- Original Message --------
Subject: Re: close(file); always necessary??
From: leledumbo <
leledumbo_cool@yahoo.co.id>
Date: Tue, June 15, 2010 4:06 am
To:
gpc@gnu.de
Why rely on implementation? One good coding practice is to close what you've
opened. AFAIK in most Pascal implementation, even if the OS will close the
file upon program exit, the buffer that contains something you write will
not be flushed. So you will lose everything you've written.
Rugxulo wrote:
>
> Hey,
> In non-standard Pascal mode, does it matter if I explicitly close
> the file or not? E.g., "close(file);", is that done automatically or
> is it implementation defined? (I'm 99% sure DOS always closes files
> upon exit.) I'm just wondering if that's a fair assumption for Linux,
> etc. (though I kinda doubt it).
>
>
>
--
View this message in context:
http://old.nabble.com/close%28file%29--always-necessary---tp28887188p28889944.html
Sent from the Gpc mailing list archive at
Nabble.com.