avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] calling function pointers via pointers ?


From: Dave Hansen
Subject: Re: [avr-gcc-list] calling function pointers via pointers ?
Date: Wed, 28 Sep 2005 15:28:59 -0400

From: Vincent Trouilliez <address@hidden>
[...]
However, something still causes me trouble apparently....

The actual/complete declaration of my "menu" data type / structure is :

struct menu {
        uint8_t options; //options to control the operation of the menu
        uint8_t nb;     //number of options present in this menu
        char    desc[][21];     //table to store the strings for each menu entry
        void (*fp[])(void);     //table to store the pointers to the functions
};

The compiler complains that :

ui.h:29: error: flexible array member not at end of struct
make: *** [main.o] Error 1

I got around this by giving a fixed size to 'desc', which worked fine
for debugging the pointer part of things, but it's otherwise no good of
course.
What's the trick ?

Sounds like you're in deep yogurt.

Do you know what a flexible array member is? Did you know you defined two of them? Did you reserve space for the function pointers?

You probably need to seperate the tables from the structure. Something like this:

  struct menu_entry
  {
     char desc[21];  // or perhaps simply "char * desc"
     void (*fp)(void);
  };
  struct menu
  {
        uint8_t options; //options to control the operation of the menu
        uint8_t nb;     //number of options present in this menu
        struct menu_entry * entries;
  };

Then use them something like

  struct menu_entry menu_x_entries[] = {
     { "opt 1", fn_x1},
     { "opt 2", fn_x2},
     { "opt 3", fn_x3}
  };
  struct menu menu_x = {0, 3, menu_x_entries};

Hopefully this is enough to get you started. You'll have to work out the pgmspace details out yourself.

Regards,
  -=Dave






reply via email to

[Prev in Thread] Current Thread [Next in Thread]