In my application I have a number of different structure variables. In all cases the members are unsigned char. I pass the structure to a function via a pointer where the various structures may have a different number of members with different names. Within the function I need to access the members in an indexed form. It is easy enough to use the first member to contain the size of the structure. If I used an array, indexing would be simple, but this would create problems down the line. Arrays aso have their problems - for example, strlen() returns a value of 0XFF if the array is uninitialised, as would be the case for an array that is to be written. I suppose I could always use an array to pass the data to/from the function and transfer between array and structure in the calling function, but that is hardly elegant programming!!!!
If I used an array, indexing would be simple, but this would create problems down the line.
What kind of problems?
Arrays aso have their problems - for example, strlen() returns a value of 0XFF if the array is uninitialised, as would be the case for an array that is to be written.
Well, strlen() isn't supposed to be used on arbitrary arrays - it only works on arrays that actually contain an ASCII string (terminated by a null character, which is how strlen determines the length).
I suppose I could always use an array to pass the data to/from the function and transfer between array and structure in the calling function, but that is hardly elegant programming!!!!
You could also just cast the structure pointer to an array pointer. I don't see why using an array in the first place should be such a big problem, though.
You could also just cast the structure pointer to an array pointer.
Oops. That should be "char pointer".
View all questions in Keil forum