Re: Pointers

From: Zeavon (zeavon@kilnar.com)
Date: 11/12/99


On Fri, 12 Nov 1999, Tony Robbins wrote:

> To take the question a little further, would there be a problem doing the
> following?
>
> int *pointer;
> CREATE(pointer, int, x);
>
> vs.
>
> int *pointer = NULL;
> CREATE(pointer, int, x);

Either one works so long as you remember to set a value to the variable
before you attempt to use it. This applies with ALL variables. Not just
pointers.

Again, I'll assert that the safest way to do that is by initializing the
variable when you declare it. If you get in the habit of doing:

int *pointer;
CREATE(pointer, int, x);

then you may forget the CREATE statement or you may decide to wait until a
later point in the code to determine what 'x' is before allocating memory
for the pointer variable. In that case, someone else (another coder on
your team) may attempt to use pointer between the declaration and the
memory allocation/initialization. This, of course, is a bad thing.

Summary: Spend the extra second to type " = NULL" or " = 0" or whatever.
It will save you hours of debugging time in the future.

--
Zeavon Calatin, MageMaster of the Realms
Spear of Insanity
http://spear.kilnar.com/    telnet://spear.kilnar.com:1066


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



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