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: David Brown
Subject: Re: [avr-gcc-list] calling function pointers via pointers ?
Date: Thu, 29 Sep 2005 09:06:17 +0200

> From: Vincent Trouilliez <address@hidden>
> [...]
> >Problem: my function pointers are in an array, within a structure, which
> >itself is accessed via pointers... oh dear.
> >
> [...]
> >//data type for a menu
> >struct menu {
> > .....;
> > .....;
> > int (*fp)()[]; //table to store all the pointers
>
> Err...  Read it from the inside-out: fp is a pointer to a function that
> returns an array of pointers to int.  I don't think that works, let alone
is
> what you want.  And you need to specify the size, and it's a good idea to
> specify the formal parameters needed by the function.  I think you mean
> something like
>
>    int (*fp[3])(void);
>
> fp is an array of 3 pointers to function taking void and returning int.
>


Just a little hint - use typedef for any types involving more than two
"bits" :

typedef int (*FInt)(void);
struct menu {
    ...
    FInt fp[3];
    ...

typedefs make the code legible and clear - if you have to think hard or read
comments to understand a type, then the code is wrong (even if it is
right!).  IMHO, of course.

mvh.,

David






reply via email to

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