Re: hmmm.... db.c:free_char()

From: James Turner (turnerjh@XTN.NET)
Date: 08/06/98


Angus Mezick <angus@EDGIL.CCMAIL.COMPUSERVE.COM> writes:

> At the very end of this function, is there any reason not to do a ch=NULL; right
> have the free(ch); call?  I think this might be a nice way to ensure
> consistancy.  But for that DT and fast aggr problem, you need to check to see
> if(ch && ch->in_room)
>
> if !ch, then ch->in_room won't be checked.

void
f(int x)
{
  x = 2;
}

int main()
{
  int y = 4;

  f(y);

  printf("%d\n", y);

  return 0;
}

Output is 4.  The problem is assigning to a passed variable only
assigns to a function's local copy.  Since C always passes by value
insteas of by reference, you can't change a parameter variable and
have it change the actual variable it was called with.  What you can
do is:

void
f(int *x)
{
  *x = 2;
}

int main()
{
  int y = 4;

  f(&y);

  printf("%d\n", y);

  return 0;
}

Which works fine, since you're not changing x, but the value x points
to.  In C++ you can pass by reference by declaring the function as
void f(int &x), where the effect you describe would work fine.  But,
since Circle is C, and making it C++ is a semi-tedious[1] exercise
left for the reader, I answer only in the context of C :)

[1] - it's not terribly bad, but it requires a lot of changes.  An
hour or so with a good editor like Emacs (hah! as if there are any
other editors like Emacs!) should do it.  There aren't any real code
changes, mostly cleanups (the bool type for one; some functions use
variables called virtual and new and delete I believe).

Chip

--
James Turner                turnerjh@pattern.net         UIN: 1102038
                            http://www.vuse.vanderbilt.edu/~turnerjh/


     +------------------------------------------------------------+
     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     | http://democracy.queensu.ca/~fletcher/Circle/list-faq.html |
     +------------------------------------------------------------+



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