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?
I think I am going to try to this recommendation: Now, a large struct will have the first data values stored identically to a smaller struct, so you may let all functions take a pointer to a struct of one size. Then let the function check the optional "data_size" field to check if a struct of the expected size was sent.
thanks a lot for a most outstanding reply!