Re: Code question re: AFK

From: Cervo (chrisf@PTD.NET)
Date: 08/31/98


> Warning 'vict' might be used uninitialized in this function (refering to
> do_tell)
When you first declare vict which is probably a char_data, how do you
declare it?  struct char_data *vict = NULL; whill get rid of any warnings,
if it is declared struct_ char_data *vict;  Hmm maybe that is a bit
confusing, if you find the second one, change it to the first one :P  I
currently don't have access to my circle code, so I can't tell if vict is
a parameter to the function, but I'm guessing it could just be declared
wrong, because vict is generally a local variable.  It is always a good
idea to initialize variables to something when you declare them.
Otherwise, a random memory location is assigned to the variable, and there
is no telling what is in there.  Therefore when you declare an int or
long, set it to 0, when you declare a float or double, set it to 0.0, when
you declare a character array or character, set it to '\0', when you
declare a pointer besides an array or pointer to a character string, set
it to NULL.
int integerVariable = 0;
double floatVariable = 0.0;
struct char_data *char_dataPointer = NULL;
char *ptrToString = NULL;
char buf2[MAX_STRING_LENGTH] = '\0';
char oneCharacter = '\0';

Those are some lines that will hopefully make sense, hehehehe if not, just
look at the quote before, I'm sure I did one of those *whistle*.  But for
the most part what I am trying to say is before you use it, assign it some
value.  Also if you are using it uninitialized and it isn't being passed
by reference, the program well probably crash.  You'll want to look into
assigning vict via get_char_vis and stuff.  Of course if it works, just
initialize the variable to get rid of the warning, although I'm guessing
it crashes.  If you have trouble and post the entire function.  I don't
even know what function you are talking about.  But if you are talking
about ACMD(do_tell) you will probably have to find the vict via
find_char_vis, although I thought that was in there via stock *shrug*.


       Cervo the redoC retsaM
If you cannot convince them, confuse them.
        -- Harry S. Truman

P.S. Wowee I couldn't have gotton a better quote :P  Hehehehe if you are
confused reply to me privately and I'll try and clairfy this :P


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