[Top][All Lists]

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

Re: [avr-gcc-list] Table of function pointers

From: Rich Neswold
Subject: Re: [avr-gcc-list] Table of function pointers
Date: Tue, 8 May 2001 13:01:57 -0500
User-agent: Mutt/1.2.5i

Wasn't it  3-May-2001, at 09:43AM, when Guy Robinson said:
> Hi,
> Can anyone explain what this error means? See source below. I can't see what
> I'm doing wrong. Thanks in advance for your help.
> Guy
> hx_2313.c:37: declaration of `FunctionTable' as array of functions
> hx_2313.c:37: Tree check: expected class 't', have 'x' (error_mark)
> confused by earlier errors, bailing out
> D:\AVRGCC\BIN\MAKE.EXE: *** [hx_2313.o] Error 1
> #include <io.h>
> #include <progmem.h>
> #define pint int __attribute__ ((progmem))
> void function0();
> void function1();
> pint *FunctionTable[2]() = {function0,function1};
> char a,b,index;
> void function0(){
>        a =b;
>   }
> void function1(){
>      b =a;
>  }
> void main(void){
> PRG_RDB(FunctionTable[index]());        // call function from table at index
> index++;
>  }

There's quite a few things that I'd question.

Your array contains pointers to functions that return a pointer to
progmem'ed data. Yet, neither 'function0' nor 'function1' return a value.

I'm also assuming that you're using the compiler option that makes "int"s 8
bits wide, because the two functions are being used in the context of an
int, but they manipulate chars.

Finally, your functions return pointers to progmem variables, yet you don't
define any variables in the progmem space.

If your question is only to find out how the array needs to be defined,
then this is how I'd try it [I chopped out the portions that don't apply to
the question]:

    #define pchar char __attribute__ ((progmem))

    typedef pchar* (*PF)(void);

    pchar* function0(void);
    pchar* function1(void);

    PF FunctionTable[2] = { function0, function1 };

By defining a new type, PF, it makes the array definition simpler.

Hope this helps....

 Rich Neswold

 efax: 1.240.536.7092
  web: www.enteract.com/~rneswold/

Attachment: pgpikbyixQcE9.pgp
Description: PGP signature

reply via email to

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