Memory Allocation To a Structure

Discussion in 'C' started by ronan_40060, Feb 7, 2009.

  1. ronan_40060

    ronan_40060 New Member

    Joined:
    Nov 25, 2008
    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    0
    Dear Experts
    I have the following Structure
    Code:
    typedef struct wf_list_workunit_fe  
                    {
                                    short int nbr_Workunits_fe;
                                    [size_is(nbr_Workunits_fe)] WF_STRUCT_WORKUNIT_FE  lst_Workunit_fe
    [*];
                    } WF_LIST_WORKUNIT_FE;
    and 
    typedef [ptr] WF_LIST_WORKUNIT_FE * WF_LIST_WORKUNIT_P_FE;
    and Now Im doing this 
    WF_LIST_WORKUNIT_FE listWU;
    memset((void*)&listWU, '\0' , sizeof(WF_LIST_WORKUNIT_FE));
    WF_LIST_WORKUNIT_P_FE ptrlistWU ;
    ptrlistWU = &listWU;
    
    Is this correct ?
     
    Last edited by a moderator: Feb 7, 2009
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    There are 2 ways to say if its correct or not.

    1. Syntactically
    2. Semantically

    For testing point 1 you should allow the compiler to say if its compiling.

    For Semantically correction we need to know what you are trying to do as well.
     
  3. ronan_40060

    ronan_40060 New Member

    Joined:
    Nov 25, 2008
    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    0
    Hi Shabbir
    Thanks for the reply ..
    WF_LIST_WORKUNIT_FE array of structure is sent as an OUT param in one of the RPC..
    Im allocating a memory for it to store all the member varibles of WF_LIST_WORKUNIT_FE in local variables

    for (int i = 0; i < ptrlistWU->nbr_Workunits_fe; i++)
    {
    retObj->workunitArray->lstWorkunit->wfStructWu.push_back(conObj.WFWuStructDceToSoap(ptrlistWU->lst_Workunit_fe));
    }
    where lstWorkunit is the local object and I have ptrlistWU->lst_Workunit_fe) that is passed to WFWuStructDceToSoap method ...
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice