Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C - C++ Learning > Is there a need...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 7 Topic 4265 of 4370
Post > Topic >>

Is there a need to fix this (possible scoping problem)?

by inquisitive@[EMAIL PROTECTED] Sep 9, 2008 at 09:53 AM

Hi Everyone,

I have a linked list I'm working on to keep track of worker nodes
(worker nodes are a client that handles requests for a server).

typedef struct Node
{
....
    char* address;  //!< address of worker
    struct Node* next; //!< Next Node
    struct Node* prev; //!< Previous Node
} Node;

Node * gTopNode = NULL;

I have a section of code that looks to me like it may contain an
error.

Given the following function (trimmed for brevity ...)

///Create a new node and add it to the end of the list
Node* CreateNode(char* address,Node* pTopNode)
{
....
    Node* pNode = NodeListFindNode(address,pTopNode);
    if(pNode == NULL)
    {
        pNode = (Node*) calloc (1,sizeof(Node));
        pNode->address = address;
        ....
    }
   .....
}

It is called as follows.



int module_init(int argc, char* argv[])
{
....
gTopNode = NodeListCreateNode("127.0.0.1",gTopNode);
....
   if(gTopNode != NULL)
       return OK;
   else
       return MODULE_FAILED
}

So my question is what will happen to gTopNode->address after
module_init returns.

A lot of places will reference it since it's a global starting point.
Will the value of address still be "127.0.0.1" or will it end up
deallocated?

Thanks in advance!
 




 7 Posts in Topic:
Is there a need to fix this (possible scoping problem)?
inquisitive@[EMAIL PROTEC  2008-09-09 09:53:33 
Re: Is there a need to fix this (possible scoping problem)?
Ben Bacarisse <ben.use  2008-09-10 01:16:33 
Re: Is there a need to fix this (possible scoping problem)?
Barry Schwarz <schwarz  2008-09-09 21:31:48 
Re: Is there a need to fix this (possible scoping problem)?
inquisitive@[EMAIL PROTEC  2008-09-10 07:16:56 
Re: Is there a need to fix this (possible scoping problem)?
Barry Schwarz <schwarz  2008-09-10 17:11:16 
Re: Is there a need to fix this (possible scoping problem)?
inquisitive@[EMAIL PROTEC  2008-09-11 12:32:04 
Re: Is there a need to fix this (possible scoping problem)?
Ben Bacarisse <ben.use  2008-09-11 23:29:12 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Nov 21 8:51:37 CST 2008.