Re: Oh man is this a bad one...

From: Michael Scott (scottm@DNS.workcomm.net)
Date: 05/09/96


On Wed, 8 May 1996, Hades wrote:

Okay, if I'm not mistaken .. you're changing the value of ch INSIDE a 
procedure then wondering why its back to normal once yer back outside.

	If that's your quandry.  Then its simple .. you can't change the 
value of ch inside a procedure and expect it to stay changed unless you 
send a reference to it.  (ie.. char_struct **) (in english a pointer to 
a character structure pointer).

	for instance .. say i have a simple routine:

void change_int (int a) {
	a++;
}

	now, say outside this routine i have a vaiable b and its equal 
to 3.  I send it to the routine and then i check it afterwards.. whammo
its still 3.  And thats because what i sent to the routine was the VALUE
of the variable and not the pointer to the variable itself.

	heres the routine you would want .. if you were actually wanting
to change the value of some int variable by sending to a procedure:

void change_int (int *a) {
	(*a)++;
}

	in this example i sent the reference to the value.. and i 
dereferenced it in the routine .. and changed it.  and when it gets back 
out of the routine  b will equal 4.

	Now back to the example Hades posted earlier and why he can still see 
all the char info even after he sends the ch variable through the 
free_char routine ... YES all the character structures have been 
released back to the system for its use,  it just hasnt got around to
reallocating it yet (and thus its still intact).

	Sorry, for the technical answer .. i KNOW this isnt CS 1.. :>

	But I had to respond with something that would hopefully make sense.

							Mike Scott
						(scottm@workcomm.net)
Ps. I have read this list for quite some time and I RARELY if ever 
answer questions.. (sorry) .. so it would really be unfair of me to take 
any part in deciding whether this list should be split. 
	Although (and Chris Austin may HATE me for this).. I due work on 
my mud late at night and I am running InterMUD.. (Manx@SaberMUD, for 
those of you who have intermud)  And if you have some question you feel 
is valid, I do quite often answer people there.

> Date: Wed, 8 May 1996 23:54:02 -0400 (EDT)
> From: Hades <tourach@servtech.com>
> To: Circle Mailing List <circle@pvv.unit.no>
> Subject: Oh man is this a bad one...
> 
> extract_char(ch)... in there it calls free_char(ch), which SHOULD free all
> memory used by a char, right? Then it frees the ch itself with free(ch) then
> ch = NULL; right?
> 
> SO when it returns from free_char, ch SHOUDL = NULL, right?
> 
> SO when it returns from extract_char, ch should be null, right?
> 
[ rest deleted ]



This archive was generated by hypermail 2b30 : 12/18/00 PST