NO

Author Topic: Structures in debugging  (Read 1993 times)

PhilG57

  • Guest
Structures in debugging
« on: February 18, 2014, 08:57:16 PM »
Hi.  If I have a little sub-routine such as:
void MyFunc(void)
{
   struct locks *gottem;
   memset(&gottem, 0, sizeof(gottem));    /* more clean code */
   ...
   ...
}

As I enter this sub-routine under debug, with the cursor at the memset call, debug shows for my 'gottem' structure + gottem, {...}, struct *, 4015c4 where "+" is the little plus sign in a box, {...} is the value of the variable, and 4015c4 is what I assume is the address of the structure.

Now I hit F11, the memset is executed and the debug window shows + gottem, NULL, struct *, and 00000000.  If I look at memory location 4015c4 it has not changed.

What is debug trying to tell me????

Thanks.

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2113
Re: Structures in debugging
« Reply #1 on: February 18, 2014, 10:04:50 PM »
You are defining 'gottem' as a pointer to a 'locks' structure.
Then, getting '&gottem,  you perform a memset on the address of the address of the structure=the pointer itself.
Then memset set to 0 the pointer, that gives you gottem=0.
Maybe you would have write:
Code: [Select]
void MyFunc(void)
{
   struct locks gottem;     //Define a structure not a pointer to.....
   memset(&gottem, 0, sizeof(gottem));    /* more clean code */
   ...
   ...
}

or
Code: [Select]
void MyFunc(void)
{
   struct locks *gottem;     //Define a pointer to structure

   gottem=&MyPreviouslyDefinedStructure;   //Assign it the address of a structure defined elsewhere
   memset(gottem, 0, sizeof(gottem));    /* pass the gottem pointer that corrctly references a locks type structure */
   ...
   ...
}
"It is better to be hated for what you are than to be loved for what you are not." - Andre Gide