From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <5de78c46509aee1450f7c6565f05ff25.axp-list@archive.invalid> X-Archive-Original-Message-ID: <9702171536.ZM1175@davros.bwh.com> Date: Mon, 17 Feb 1997 15:36:28 -0600 From: Bryan W. Headley Subject: Re: fclose() (fwd) In-Reply-To: On Feb 17, 4:18pm, Jim Nance wrote: > Subject: Re: fclose() (fwd) > Forwarded message: > > > > In professional world, I've seen far too many programs that close all > > > handles at termination, regardless of whether if known that handle is > > > open or not. It WOULD be nice to legislate good programming, I agree... > > I wonder why they bother. They all get closed when the program terminates. > But thats not what I am writing about. A little gem of experience I gained > under SunOS is that the code sequence: > > FILE *f1, *f2; > > f1 = fopen("file1", "r"); > fclose(f1); > f2 = fopen("file2", "r"); > fclose(f1); /* Second close of f1 */ > > will close f2 when you call fclose on f1 the second time because the second > fopen() returns the same pointer that the first fopen() returned. Ie the > file pointers get recycled. This can be most unpleasant. I guess my point > is that even if we make fclose() not crash, there is no guarantee that its > going to run like the programmer intended. > Yeech! I wonder what it does with three potential file *'s. That downright sucks; it's nice that they keep their FILE *'s in a stack -- Bryan W. Headley Home: bheadley@interaccess.com 211 East Pineview Drive Office: bwh@abnamro.com Round Lake Park, IL 60073 Phone: 847 740-1446 -- To unsubscribe: send e-mail to axp-list-request@redhat.com with 'unsubscribe' as the subject. Do not send it to axp-list@redhat.com