Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Dynamic array of structures containing yet another dynamic array of structures (http://www.go4expert.com/forums/dynamic-array-structures-containing-t12010/)

innqubus 11Jul2008 08:03

Dynamic array of structures containing yet another dynamic array of structures
 
Hello,
I want to create an array of structures wherein the array is dynamic. Inside the parent structure, there is another array of structures which is also dynamic. I am not able to resolve some issues while trying to compile it...Kindly help me out.
Firstly, i have the code below showing the structure details
Code:

typedef struct
{
        uint8_t dlmAcid;
        uint8_t dlmHarqEBCount;
        uint8_t dlmAisn;
} STRUCTPAD DlmAcidInfo_t;

typedef struct
{
        uint8_t cidInMap;
        uint8_t mapharqFlag;
        uint8_t noOfEBs;
        uint8_t mcsNo;
        uint8_t mapharqMode;
        uint8_t ackchAlloc;
        uint8_t mapAcidCount;
        DlmAcidInfo_t DlmAcid;
} STRUCTPAD CidInfoInMap_t;

typedef struct
{
        uint8_t noOfCids;
        CidInfoInMap_t cidInfoInMap;
} STRUCTPAD ZoneInfoInMap_t;

typedef struct
{
        uint8_t dlFrameNo;
        ZoneInfoInMap_t zoneInfoInMap;
} STRUCTPAD HARQAckInfo_t;

Here is my code, i have written. It incomplete as i am yet to free the memory.
Code:

#include<stdio.h>
#include<stdint.h>
#define STRUCTPAD  __attribute__((__packed__))
typedef struct
{
        uint8_t dlmAcid;
        uint8_t dlmHarqEBCount;
        uint8_t dlmAisn;
} STRUCTPAD DlmAcidInfo_t;

typedef struct
{
        uint8_t cidInMap;
        uint8_t mapharqFlag;
        uint8_t noOfEBs;
        uint8_t mcsNo;
        uint8_t mapharqMode;
        uint8_t ackchAlloc;
        uint8_t mapAcidCount;
        DlmAcidInfo_t DlmAcid;
} STRUCTPAD CidInfoInMap_t;

typedef struct
{
        uint8_t noOfCids;
        CidInfoInMap_t cidInfoInMap;
} STRUCTPAD ZoneInfoInMap_t;

typedef struct
{
        uint8_t dlFrameNo;
        ZoneInfoInMap_t zoneInfoInMap;
} STRUCTPAD HARQAckInfo_t;

int main()
{
int q,z,x,a;
int noOfZones =2;
#if 0
HARQAckInfo_t temp;
HARQAckInfo_t *harqInfo;
harqInfo = &temp;
#endif

HARQAckInfo_t **harqInfo = NULL;
ZoneInfoInMap_t **zoneInfoInMap = NULL;
CidInfoInMap_t **cidInfoInMap = NULL;
DlmAcidInfo_t **DlmAcid = NULL;

for(q=0; q<1; q++)
{
harqInfo = (HARQAckInfo_t**)realloc(harqInfo, (q+1)*sizeof(HARQAckInfo_t*));
harqInfo[q]= (HARQAckInfo_t*)malloc(sizeof(HARQAckInfo_t));
/*Begin filling HARQAckInfo_t based on no. of zones which you can know dynamically */
harqInfo[q]->dlFrameNo = 100;
for(z=0; z<noOfZones; z++)
        {
        harqInfo[q]->zoneInfoInMap = (ZoneInfoInMap_t**)realloc(harqInfo[q]->zoneInfoInMap,(z+1)*sizeof(ZoneInfoInMap_t*));
        harqInfo[q]->zoneInfoInMap[z] = (ZoneInfoInMap_t*)malloc(sizeof(ZoneInfoInMap_t));
        harqInfo[q]->zoneInfoInMap[z]->noOfCids = 50;
        for(x =0; x<harqInfo[q]->zoneInfoInMap[z]->noOfCids; x++)
                {
                harqInfo[q]->zoneInfoInMap[z]->cidInfoInMap = (CidInfoInMap_t**)realloc(harqInfo[q]->zoneInfoInMap[z]->cidInfoInMap,(x+1)*sizeof(CidInfoInMap_t*));
                harqInfo[q]->zoneInfoInMap[z]->cidInfoInMap[x] = (CidInfoInMap_t*)malloc(sizeof(CidInfoInMap_t));
                harqInfo[q]->zoneInfoInMap[z]->cidInfoInMap[x]->cidInMap = 5;
                harqInfo[q]->zoneInfoInMap[z]->cidInfoInMap[x]->mapharqFlag = 1;
                harqInfo[q]->zoneInfoInMap[z]->cidInfoInMap[x]->noOfEBs = 5;
                harqInfo[q]->zoneInfoInMap[z]->cidInfoInMap[x]->mcsNo = 4;
                if(harqInfo[q]->zoneInfoInMap[z]->cidInfoInMap[x]->mapharqFlag ==1)
                {
                harqInfo[q]->zoneInfoInMap[z]->cidInfoInMap[x]->mapharqMode = 0;
                harqInfo[q]->zoneInfoInMap[z]->cidInfoInMap[x]->ackchAlloc = 0;
                harqInfo[q]->zoneInfoInMap[z]->cidInfoInMap[x]->mapAcidCount = 20;
                for(a=0; a<harqInfo[q]->zoneInfoInMap[z]->cidInfoInMap[x]->mapAcidCount; a++)
                        {
                        harqInfo[q]->zoneInfoInMap[z]->cidInfoInMap[x]->DlmAcid = (DlmAcidInfo_t**)realloc(harqInfo[q]->zoneInfoInMap[z]->cidInfoInMap[x]->DlmAcid,(a+1)*sizeof(DlmAcidInfo_t*));
                        harqInfo[q]->zoneInfoInMap[z]->cidInfoInMap[x]->DlmAcid[a] = (DlmAcidInfo_t*)malloc(sizeof(DlmAcidInfo_t));
                        harqInfo[q]->zoneInfoInMap[z]->cidInfoInMap[x]->DlmAcid[a]->dlmAcid = 5;
                        harqInfo[q]->zoneInfoInMap[z]->cidInfoInMap[x]->DlmAcid[a]->dlmHarqEBCount = 5;
                        harqInfo[q]->zoneInfoInMap[z]->cidInfoInMap[x]->DlmAcid[a]->dlmAisn = 1;
                        }
                }
                }
        }
}
}

I am getting various warnings and errors as i am sure that i have done mistakes in declaring structures and assigning memory to it.Kindly see these errors after compilation
Code:

gcc dyn.c
dyn.c: In function `main':
dyn.c:52: warning: cast to pointer from integer of different size
dyn.c:58: warning: cast to pointer from integer of different size
dyn.c:58: error: incompatible types in assignment
dyn.c:59: error: subscripted value is neither array nor pointer
dyn.c:60: error: subscripted value is neither array nor pointer
dyn.c:61: error: subscripted value is neither array nor pointer
dyn.c:63: error: subscripted value is neither array nor pointer
dyn.c:63: error: subscripted value is neither array nor pointer
dyn.c:63: warning: cast to pointer from integer of different size
dyn.c:64: error: subscripted value is neither array nor pointer
dyn.c:65: error: subscripted value is neither array nor pointer
dyn.c:66: error: subscripted value is neither array nor pointer
dyn.c:67: error: subscripted value is neither array nor pointer
dyn.c:68: error: subscripted value is neither array nor pointer
dyn.c:69: error: subscripted value is neither array nor pointer
dyn.c:71: error: subscripted value is neither array nor pointer
dyn.c:72: error: subscripted value is neither array nor pointer
dyn.c:73: error: subscripted value is neither array nor pointer
dyn.c:74: error: subscripted value is neither array nor pointer
dyn.c:76: error: subscripted value is neither array nor pointer
dyn.c:76: error: subscripted value is neither array nor pointer
dyn.c:76: warning: cast to pointer from integer of different size
dyn.c:77: error: subscripted value is neither array nor pointer
dyn.c:78: error: subscripted value is neither array nor pointer
dyn.c:79: error: subscripted value is neither array nor pointer
dyn.c:80: error: subscripted value is neither array nor pointer

Note: All the RValues (constants) assigned in the code are just for testing purposes.. these values are known dynamically when run on real time.
Kindly please help me out :-|
Thanks in advance.
Btw, i referred this here as an example to implement this


All times are GMT +5.5. The time now is 10:53.