Login
User Name:

Password:



Register
Forgot your password?
Vote for Us!
auth_update crash
Dec 23, 2017, 10:15 pm
By Remcon
check_tumble
Dec 18, 2017, 7:21 pm
By Remcon
parse description bug
Dec 15, 2017, 10:08 pm
By Remcon
Couple bugs
Dec 12, 2017, 5:42 pm
By Remcon
Bug in disarm( )
Nov 12, 2017, 6:54 pm
By GatewaySysop
LoP 1.46
Author: Remcon
Submitted by: Remcon
LOP 1.45
Author: Remcon
Submitted by: Remcon
LOP Heroes Edition
Author: Vladaar
Submitted by: Vladaar
Heroes sound extras
Author: Vladaar
Submitted by: Vladaar
6Dragons 4.3
Author: Vladaar
Submitted by: Vladaar
Users Online
CommonCrawl, Yahoo!

Members: 0
Guests: 7
Stats
Files
Topics
Posts
Members
Newest Member
478
3,708
19,242
612
Jacki72H
Today's Birthdays
There are no member birthdays today.
Related Links
» SmaugMuds.org » General » General Discussions » Coding practice of closing fi...
Forum Rules | Mark all | Recent Posts

Coding practice of closing files
< Newer Topic :: Older Topic >

Pages:<< prev 1 next >>
Post is unread #1 Sep 5, 2005, 2:48 pm
Go to the top of the page
Go to the bottom of the page

Gatz
Apprentice
GroupMembers
Posts60
JoinedJul 25, 2005

I'm sort of curious because I've noticed Samson does this a lot and a few other people too, but when they close a file they also set the file variable to null. I'm sort of wondering why they do that? I suppose it has a good reason but I'm not exactly sure. I hope this isn't a common sense thing because I've tired to figure out why with no luck.
Here is just quick example of what I mean in code:
fclose(fp);
fp = NULL;


Instead of just:
fclose(fp);
       
Post is unread #2 Sep 5, 2005, 3:06 pm
Go to the top of the page
Go to the bottom of the page

Samson
Black Hand
GroupAdministrators
Posts3,639
JoinedJan 1, 2002

It's a safeguard thing mainly. Makes sure that there's no possible way the file handle could be picked up elsewhere and used. Mainly came about after Redhat 6 and the GCC compiler it had began throwing mysterious errors because only fclose(fp); was being used. It took some time to figure out and since then pretty much every file I close also gets NULL'd immediately.
       
Post is unread #3 Sep 6, 2005, 7:52 am
Go to the top of the page
Go to the bottom of the page

Greven
Magician
GroupMembers
Posts204
JoinedMar 5, 2005

Using a macro is a good way to do this as well. mine is just FCLOSE and I did a perl command line to replace all fclose with FCLOSE, worked great. I beleive that I got the macro from AFKmud.
       
Pages:<< prev 1 next >>