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

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

Re: [avr-gcc-list] Array of pointers to functions


From: Russell Shaw
Subject: Re: [avr-gcc-list] Array of pointers to functions
Date: Mon, 19 Jul 2004 02:31:15 +1000
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040528 Debian/1.6-7

Royce & Sharal Pereira wrote:
Hi, all,

I'm trying to call a function from an array, like this..

char f_cnt;

void fun1(void)
    {
        //some code
    }
//---------------------
void fun2(void)
    {
        //some code
    }
//---------------------
void fun3(void)
    {
        //some code
    }
//---------------------

void (*call_fun[])() PROGMEM = { fun1, fun2, fun3};  //This puts the addresses 
in code memory(seems
so from the .lst file).
//----------------------
void main(void)
    {
        (*call_fun[f_cnt])();  //But here I get a 'ld' instruction. How to 
cause an LPM instruction
to get the function address before the 'icall' ?
    }
//---------------------

Many Thanks,

--Royce.

I'd try:

  typedef (*call_fun)(void);

  call_fun cfa[]={fun1,fun2,fun3};

  void main(void)
  {
    cfa[f_cnt]();
  }


reply via email to

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