TIP: Click on subject to list as thread! ANSI
echo: os2prog
to: Thomas Seeling
from: Mike Bilow
date: 1995-08-24 17:43:18
subject: tidbits

Thomas Seeling wrote in a message to Richard Illes:

 RI> code, Visual C zero's out the FILE pointer after a fclose() and any

 TS> I cannot imagine that. The prototype is "int fclose(FILE
 TS> *)", so how should it be possible to zero the pointer
 TS> itself? To do what you tell here, it would have to be
 TS> something like "int fclose(FILE **)".

The C language looks at streams, which are associated with FILE structs,
while the operating system looks at handles, which are usually of type int.
 As a practical matter, the C run-time library would keep the operating
system handle as a member of the FILE struct, and it is probably this which
is being zeroed out.  Ordinarily, the FILE struct should be treated by the
programmer as a black box provided by the C run-time library.

 RI> further fprintf() to this pointer causes nothing to happen..

 TS> fprintf(NULL,...) should cause an exception, not "nothing".

The pointer is probably valid, pointing at an deinitialized FILE struct
containing an invalid file handle.  Attempting to write to such a stream
would have undefined consequences, but might not cause any exception.  For
example, if the file handle happened to have been zeroed, then the effect
would be something like fprintf(stdin,...), which is valid but meaningless.

 RI> CSet just leaves the FILE pointer a mess which causes a trap on 
 RI> fprintf().

 TS> This is up to the compiler implementors.

No.  As you note, fclose() takes a pointer to FILE as an argument, and it
cannot modify the pointer itself.  What the writer means is that the FILE
struct pointed to is modified by fclose(), which is expected.
 
-- Mike


---
* Origin: N1BEE BBS +1 401 944 8498 V.34/V.FC/V.32bis/HST16.8 (1:323/107)
SEEN-BY: 105/42 620/243 711/401 409 410 413 430 807 808 809 934 955 712/407
SEEN-BY: 712/515 628 704 713/888 800/1 7877/2809
@PATH: 323/107 150 3615/50 396/1 270/101 105/103 42 712/515 711/808 809 934

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.