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

Structures

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!!!!

Parents
  • I agree about strlen(). That's why I could not use it. I want an index because I will be doing a variable-length sequential read/write to an I2C device, and the calling program is more understandable if structures are used. E.G one structure may contain four bytes for time while another structure may contain 10 bytes of operating parameters. For a Real Time Clock I would prefer to use Time.Seconds rather than Time[i]. This whole thing is no big deal - I am simply interested in code quality and readability as well as functionality.

Reply
  • I agree about strlen(). That's why I could not use it. I want an index because I will be doing a variable-length sequential read/write to an I2C device, and the calling program is more understandable if structures are used. E.G one structure may contain four bytes for time while another structure may contain 10 bytes of operating parameters. For a Real Time Clock I would prefer to use Time.Seconds rather than Time[i]. This whole thing is no big deal - I am simply interested in code quality and readability as well as functionality.

Children
No data