Using a struct array

I’m trying another approach at a need and thought of using an array of type struct. The declaration seems to be fine, but when I try to assign something to a member, I’m getting a nondescript compiler error message (the darn orange one at the bottom of the Dev screen that seems to like me).

Can someone provide some insight as to what I’m doing wrong?

Here’s a snippet of the troublesome code:

struct MyObject         
 {
     uint32_t sec;       // 4 bytes time stamp in epoch format
     uint32_t vbat;      // 4 bytes
     uint16_t wlev;      // 2 bytes
     uint8_t dummy2;     // 1 byte
     uint8_t dummy3;     // 1 byte
     uint8_t dummy4;     // 1 byte
     uint8_t fault;      // 1 byte
 };

retained MyObject dufus[50];

dufus[17].sec = 17;

@ctmorrison, if you remove the retained typing, does it work?

So, I moved the assignment statement duffs[17].sec = 17; into setup(); and all is good. I guess I have to admit my ignorance about what can “legally” be outside of setup(); and loop(); other than the obvious declarations.

2 Likes