SOLVED: Too Many Initializers errors when initializing global array of structs

I have been paring down my hoped for code to try to get something that compiles, but am still failing. I started with structures with “flexible array members” as the last element, but have since moved to simple, statically sized arrays. Nothing could be simpler, right? Still can’t seem to get the aggregate initialization correct. Here’s code that illustrates the problem. Hoping someone can tell me what I’m doing wrong. I’m sure it’s simple, but I’m just not seeing it.

/////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////
// COLOR CONSTANTS
/////////////////////////////////////////////////////////
#define RED          0x00FF0000
#define GREEN        0x0000FF00
#define BLUE         0x000000FF
#define PURPLE       0x00800080
#define YELLOW       0x00FFFF00
#define ORANGE       0x00FFA500
#define LUNCH        ORANGE
#define ASPIRE       ORANGE
#define OUTOFCLUSTER ORANGE


/////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////
// SCHEDULE RELATED STRUCTURE DEFINITIONS
/////////////////////////////////////////////////////////
typedef struct _Period
{
  bool     valid;
  uint8_t  begH;
  uint8_t  begM;
  uint8_t  endH;
  uint8_t  endM;
  uint32_t aCol;
  uint32_t bCol;
  uint32_t cCol;
  uint32_t dCol;
} Period;

#define MAX_PERIODS 10
typedef struct _BellSched
{
  Period Periods[MAX_PERIODS];
} BellSched;

typedef struct _SingleDay
{
  bool        valid;
  uint8_t     Y;
  uint8_t     M;
  uint8_t     D;
  BellSched*  dayType;
  uint8_t     dayLetter;
} SingleDay;

#define MAX_DAYS  180
typedef struct _Calendar
{
  SingleDay Days[MAX_DAYS];
} Calendar;

BellSched NormalDay=
{
  {true,8,0,8,50,OUTOFCLUSTER,RED,OUTOFCLUSTER,YELLOW},
  {true,8,52,9,40,RED,YELLOW,YELLOW,OUTOFCLUSTER},
  {true,9,42,9,52,ASPIRE,ASPIRE,ASPIRE,ASPIRE},
  {true,9,54,10,42,YELLOW,OUTOFCLUSTER,RED,RED},
  {true,10,44,11,32,GREEN,OUTOFCLUSTER,BLUE,GREEN},
  {true,11,34,12,23,OUTOFCLUSTER,BLUE,GREEN,PURPLE},
  {true,12,25,12,46,LUNCH,LUNCH,LUNCH,LUNCH},
  {true,12,48,13,36,BLUE,PURPLE,PURPLE,OUTOFCLUSTER},
  {true,13,38,14,26,PURPLE,GREEN,OUTOFCLUSTER,BLUE},
};

const Calendar TheCalendar=
{
  {true,2018,9,4,&NormalDay,'A'},
  {true,2018,9,5,&NormalDay,'B'},
};

void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:

}

And here are the errors I get:

sketch_jan03a:66:1: error: too many initializers for 'BellSched {aka _BellSched}'

 };

 ^

sketch_jan03a:72:1: error: too many initializers for 'const Calendar {aka const _Calendar}'

 };

 ^

exit status 1
too many initializers for 'BellSched {aka _BellSched}'

Why do you make single item structs instead of using an array directly? So make 'NormalDay' an array (and then plural would make sense) of type 'Period'.

It looks like that was the intent. There are a couple of places where you missed out the suffix. e.g.:

BellSched NormalDay=

Was likely supposed to be:

BellSched NormalDay[]=

Many thanks, wildbill! Adding the and then removing the & from NormalDay (which I didn't think I should need...) did the trick.

But why have the middle useless BellSched struct in between at all?

Not sure why you might think it useless, but this is a minimal example to show the error. In the full code, there are multiple Bell Schedules, and each day in the Calendar will have a pointer to the appropriate bell schedule for that day.

So? All the BellSched struct holds is a single array. So why bother with a struct? Stri=ucts with a single array are pretty useless... Let's group a single thing....

I've helped two of my kids survive their introductory programming classes, and always express great sympathy for compiler (& interpreter) writers who have to come up with useful error messages when parsing doesn't work out. As is nearly always the case, once I understood the problem, the error message makes perfect sense. Sigh...

septillion:
So? All the BellSched struct holds is a single array. So why bother with a struct? Stri=ucts with a single array are pretty useless... Let's group a single thing....

The original intent was to have a structure that included two fields -- a count of periods, then a flexible array member of periods. The initialized data were also originally in PROGMEM but I kept paring down to simpler code to get to the simplest example I could that illustrated the problem. Now having solved that, I can work on re-introducing the more complex aspects and see if those fail or not, since I have now (thanks to y'all) conquered that basic error.

Now that makes sense. Thanks for the effort of making a MCVE! But only looking at that, BellSched just didn't make sense :slight_smile:

You're welcome -- nothing's perfect, right? :slight_smile: