delorie.com/archives/browse.cgi | search |
From: | horst DOT kraemer AT gmx DOT de (Horst Kraemer) |
Newsgroups: | comp.os.msdos.djgpp |
Subject: | Re: File Pointer. |
Date: | Sat, 29 Apr 2000 09:25:40 GMT |
Lines: | 31 |
Message-ID: | <390aa5e5.50398765@news.cis.dfn.de> |
References: | <8ebgps$5qd$1 AT nnrp1 DOT deja DOT com> |
NNTP-Posting-Host: | brln-3e357ce6.pool.mediaways.net (62.53.124.230) |
X-Trace: | fu-berlin.de 957000273 9447811 62.53.124.230 (16 [27606]) |
X-Newsreader: | Forte Free Agent 1.11/32.235 |
To: | djgpp AT delorie DOT com |
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp |
Reply-To: | djgpp AT delorie DOT com |
On Fri, 28 Apr 2000 08:06:26 GMT, hank_heng <hank_heng AT hotmail DOT com> wrote: > If I have a File Pointer, how do I know I that file pointer is still > pointing to a stream or it is already close ? You cannot by just inspecting or acessing the pointer value. In fact inspecting or acessing the pointer value of a FILE* after closing the file already may induce undefined behaviour of the program. Therefore it is mandatory to store this information in a separate place - or to set the pointer variable to 0 before opening and after closing a file. FILE*fp = 0; ... fp = fopen(...); ... fclose(fp); fp=0; But there may still be an inconsitency problem with this technique if several pointer variables point to the same file. Therefore the only safe technique would be a correct program design where you simply "know" at any time if a specific file is open by recording this knowledge in some separate variable which is acessible to the modules which need this information. Regards Horst
webmaster | delorie software privacy |
Copyright © 2019 by DJ Delorie | Updated Jul 2019 |