Problem assigning to structures under IDE 1.0.5

The code below works under IDE 1.0. Under 1.0.5 I get this error message:

test.ino: In function ‘void setup()’:
test:31: error: expected primary-expression before ‘{’ token

And here is the code. I've marked the line to which the error message applies. This was part of a much longer 800 line sketch but I've stripped out everything but the section of code that's provoking the error. Being new to C I've looked in various books and tried searching about structures without finding anything useful. I would initialize the menu structures at the time they are declared but because they are self-referential then all need to exist before they are assigned to.

Anyone know what I'm doing wrong and/or why it works under 1.0 but not under 1.05? Thanks.

struct Menu {
  char *Text;        //Pointer to our text
  void (*Action)();  //Pointer to our action routine
  struct Menu *Next; //Pointer to the next menu entry at this level
  struct Menu *Prev; //Pointer to the previous menu entry at this level
  struct Menu *Down; //Pointer to the menu entry one level down
  struct Menu *Up;   //Pointer to our parent
};

struct Menu Menu00;
struct Menu Menu01;
struct Menu Menu02;
struct Menu Menu03;
struct Menu Menu04;
struct Menu Menu05;
struct Menu Menu06;
struct Menu Menu07;
struct Menu Menu08;
struct Menu Menu09;
struct Menu Menu10;
struct Menu Menu11;
struct Menu Menu12;
struct Menu Menu13;
struct Menu Menu14;
struct Menu Menu15;
struct Menu Menu16;

void setup()
{  
    Menu00 = { "Run",    NULL, &Menu01, NULL   , NULL   , NULL    }; // This line gets the error message----------
    Menu01 = { "Setup",  NULL, &Menu13, &Menu00, &Menu02, NULL    };
    Menu02 = { "Times",  NULL, &Menu09, NULL   , &Menu03, &Menu01 };
    Menu03 = { "Dev",    NULL, &Menu04, NULL   , NULL   , &Menu02 };
    Menu04 = { "Stop",   NULL, &Menu05, &Menu03, NULL   , &Menu02 };
    Menu05 = { "Fix1",   NULL, &Menu06, &Menu04, NULL   , &Menu02 };
    Menu06 = { "Fix2",   NULL, &Menu07, &Menu05, NULL   , &Menu02 };
    Menu07 = { "Wash1",  NULL, &Menu08, &Menu06, NULL   , &Menu02 };
    Menu08 = { "Wash2",  NULL, NULL   , &Menu07, NULL   , &Menu02 };
    Menu09 = { "Fixes",  NULL, &Menu10, &Menu02, NULL   , &Menu01 };
    Menu10 = { "Washer", NULL, &Menu11, &Menu09, NULL   , &Menu01 };
    Menu11 = { "Speed",  NULL, &Menu12, &Menu10, NULL   , &Menu01 };
    Menu12 = { "Accel",  NULL, NULL   , &Menu11, NULL   , &Menu01 };
    Menu13 = { "Test",   NULL, NULL   , &Menu01, &Menu14, NULL    };
    Menu14 = { "Opt",    NULL, &Menu15, NULL   , NULL   , &Menu13 };
    Menu15 = { "Ma",     NULL, &Menu16, &Menu14, NULL   , &Menu13 };
    Menu16 = { "Mb",     NULL, NULL   , &Menu15, NULL   , &Menu13 };
}

void loop()
{
}

You try to fill a structure runtime with more than one element.
I have never done that, I think it is not possible.

You can fill the structure with values like that when declaring the structure.

In runtime, do it like this:

Menu00.Text = "Run";
.... and so on

Is it using a menu library ? Are there examples for the menu library ?

Perhaps this might work:

struct Menu_t {
  const char *Text;        //Pointer to our text
  void (*Action)();        //Pointer to our action routine
  struct Menu_t *Next; //Pointer to the next menu entry at this level
  struct Menu_t *Prev; //Pointer to the previous menu entry at this level
  struct Menu_t *Down; //Pointer to the menu entry one level down
  struct Menu_t *Up;   //Pointer to our parent
};

struct Menu_t Menu[17] = {
  { "Run",    NULL, &Menu[1], NULL   , NULL   , NULL },
  { "Setup",  NULL, &Menu[13], &Menu[0], &Menu[2], NULL },
  { "Times",  NULL, &Menu[9], NULL   , &Menu[3], &Menu[1] },
  { "Dev",    NULL, &Menu[4], NULL   , NULL   , &Menu[2] },
  { "Stop",   NULL, &Menu[5], &Menu[3], NULL   , &Menu[2] },
  { "Fix1",   NULL, &Menu[6], &Menu[4], NULL   , &Menu[2] },
  { "Fix2",   NULL, &Menu[7], &Menu[5], NULL   , &Menu[2] },
  { "Wash1",  NULL, &Menu[8], &Menu[6], NULL   , &Menu[2] },
  { "Wash2",  NULL, NULL   , &Menu[7], NULL   , &Menu[2] },
  { "Fixes",  NULL, &Menu[10], &Menu[2], NULL   , &Menu[1] },
  { "Washer", NULL, &Menu[11], &Menu[9], NULL   , &Menu[1] },
  { "Speed",  NULL, &Menu[12], &Menu[10], NULL   , &Menu[1] },
  { "Accel",  NULL, NULL   , &Menu[11], NULL   , &Menu[1] },
  { "Test",   NULL, NULL   , &Menu[1], &Menu[14], NULL    },
  { "Opt",    NULL, &Menu[15], NULL   , NULL   , &Menu[13] },
  { "Ma",     NULL, &Menu[16], &Menu[14], NULL   , &Menu[13] },
  { "Mb",     NULL, NULL   , &Menu[15], NULL   , &Menu[13] },
};

void setup()
{  
}

void loop()
{
}

CamFarnell:
Anyone know what I’m doing wrong and/or why it works under 1.0 but not under 1.05? Thanks.

I don’t understand how it could have worked under any IDE version. There is a fundamental difference between initialisation and assignment. The syntax you’re using is valid for initialisation. It is not valid for assignment.

struct Menu_t Menu = { "Run",    NULL, &MenuFoo, NULL   , NULL   , NULL }; // valid initialisation syntax

Menu = { "Run",    NULL, &MenuFoo, NULL   , NULL   , NULL }; // invalid assignment syntax

I would look for solutions that initialise the menu array with the correct values, and not try to assign values to it in setup().

Why do you have "struct Menu Menu00;" I thought it should just be "Menu Menu00;" ?

...R

Why do you have "struct Menu Menu00;" I thought it should just be "Menu Menu00;" ?

You are correct, however it is valid though and a left over from C, and as a result people often think its needed.

PeterH has pointed out the fundamentals. C++14 will allow compound literals, and are currently supported by GCC, you can use:

Menu_t Menu = { "Run",    NULL, &MenuFoo, NULL   , NULL   , NULL }; // valid initialisation syntax

Menu = ( Menu_t ){ "Run",    NULL, &MenuFoo, NULL   , NULL   , NULL }; // valid assignment syntax

pYro_65:
PeterH has pointed out the fundamentals. C++14 will allow compound literals, and are currently supported by GCC, you can use:

Though Arduino does not use C++14 - the version of GCC used is ancient, it doesn't even support C++11.

OK, I can certainly use forms like:

Menu00.Text = "Run";

It’s long-winded but works. Trying this form:

Menu00 = (Menu_t) { "Run",    NULL, &Menu01, NULL   , NULL   , NULL    };

yields:

test:32: error: cannot convert ‘Menu_t*’ to ‘Menu*’ in initialization

My originally posted code works fine under IDE 1.0 (the one that comes with Ubuntu 12.04 LTS). Although I’ve loaded 1.0.5, I still have 1.0 and my code (and indeed my 800+ line application) works fine under it. I’m new to C/C++ but in any language it is unusual for supported features to go away (well, except for Python 3.0 but that’s another story) hence my post to this forum. My thanks to all who replied.

No one uses it yet as far as I know, it is a future revision, C++11 is the recommended standard. GCC does however support compound literals, even Arduinos ancient version.

@CamFarnell, if the struct/class type is called Menu, then change Menu_t to Menu.

Menu00 = (Menu) { “Run”, NULL, &Menu01, NULL , NULL , NULL };