[Top][All Lists]

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

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

From: Joerg Wunsch
Subject: Re: [avr-gcc-list] calling function pointers via pointers ?
Date: Wed, 28 Sep 2005 14:20:40 +0200 (MET DST)

Vincent Trouilliez <address@hidden> wrote:

> struct menu {
>       .....;
>       .....;
>       int (*fp)()[];  //table to store all the pointers
> };

Better declare them in a prototyped fashion:

        int (*fp)(void)[];

> //definition for a menu
> const struct menu __ATTR_PROGMEM__ menu_foo = {
>       .....,
>       .....,
>       {fn1, fn2, ... }
> };

Don't forget to pull out each entry from progmem.  It's probably best
to copy over an entire struct menu item at a time using memcpy_P(),
as opposed to copy in each of the struct elements individually.

> //run the specified menu using the structure passed as argument
> void menu_run(const struct menu * p)
> {
>       int r;
>       .....
>       r = (p->fp[0])();       //call the first function

Basically yes (I think), but *p needs to be in RAM already.

J"org Wunsch                                           Unix support engineer
address@hidden        http://www.interface-systems.de/~j/

reply via email to

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