I've just started to use typedefs for the first time, and I haven't used structures a whole lot either, though I understand them very well.
I've created a type call Max7219_t
as follows:
typedef struct {
uint16_t digit1,
uint16_t digit2,
uint16_t digit3,
uint16_t digit4,
uint16_t digit5,
uint16_t digit6
uint16_t digit7,
uint16_t digit8,
uint16_t intensity,
uint16_t _shutdown,
uint16_t scanl,
uint16_t testmode,
uint16_t decodetype } Max7219_t;
Later in the code, after I've declared a variable of this type and added values, I need to transfer each byte in the struct
one at a time, ideally in a for
loop.
Is there any way to do this besides referring to each member directly (i.e., *display->digit1
, then *display->digit2
etcetera)? Essentially, is there a way to enumerate each entry the same way you'd do so with an array?
I don't want to just convert the whole thing to an array, because I almost certainly will add different types to this and other structures later on during development.
I feel like I'm missing something obvious here. I was thinking I could just increment a pointer, but because structure members aren't all the same size, I have a feeling this doesn't work like it does with pointers to arrays. Plus, when iterating through a for
loop, I'm not sure if something like for(q = 0; q != sizeof(Max7219_t); q++)
would work either.
Any help is much appreciated!