This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Can you suggest a better way?

Hello,

This is not a Keil related question - but either way I was hoping to hear some refreshing ideas...
I have a simple data structure, like this:

typedef struct
{
        int32s  id ;
        int32s  offset ;
        int32s  ptr1[ELEMENT] ;
        int32s  ptr2[ELEMENT] ;
        int32s  ptr3[ELEMENT] ;
} my_struct ;

The module that uses this structure offers several interfaces that expect a pointer to "my_struct".
I'm working in C, so how can I best tackle the need for an exact data structure, but with different sizes of the embedded arrays?

typedef struct
{
        int32s  id ;
        int32s  offset ;
        int32s  ptr1[3*ELEMENT] ;
        int32s  ptr2[3*ELEMENT] ;
        int32s  ptr3[3*ELEMENT] ;
} my_struct2 ;

Obviously I cannot use the existing interfaces with a pointer to "my_struct2" as the offsets of the arrays after "ptr1" have changed.
I don't want to use dynamic memory allocation.
Can you suggest a better way?

0