Re: Pointers

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


On Fri, 12 Nov 1999, Chris Gilbert wrote:

> Zeavon Calatin wrote:
> >
> > It's like wearing your seatbelt... So long as you don't get in a wreck, it's
> > safe to not wear one.
> >
> > Basically, NOT explicity setting pointers to NULL is just asking for
> > trouble.
>
> Something probably worth noting is that VC++ 6 does intialise things
> (not sure if that's debug mode only) to 0xcdcdcdcd.  Or it's something
> like that, in which case you're definetly asking for trouble not doing
> so.  Never assume anything about C, or your compiler.

Again... You're using something as a safety net, but you are not explicity
writing your code to be safe. What if they turn off that "feature" (it's a
bug in my mind) in VC 7? All of a sudden the code that worked perfectly
before is horribly broken and crash prone when you upgrade your compiler.
Better safe than sorry. Most coders I know type at some insane rate which
means typing the extra characters " = NULL" is nothing more than a split
second finger flurry.

> For local variables it's probably less of a problem, as you normally
> define things fairly quickly, and gcc does warn if something is possibly
> unintialised before use.

Global, local, whatever. Regardless of the scope of the variable it should
always be initialized before being used. The best way of insuring this is
to initialize the variable when you declare it. Of course, if you are
using C++, this may not always be an option if you are using polymorphism
or vectors or some other such creatures.

--
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