Re: Some issues with array of pointers to functions
Bob Paddock <[email protected]>
| Newsgroups | gmane.comp.hardware.avr.gcc |
|---|---|
| Message-ID | <CAOuGh88CM09d9xziXTkGHbVaTaHeyd07u8uQyqB9A4VUcOc9_w@mail.gmail.com> |
> __flash void (*funcArray[])(void) = { func1, func2, func3 } ;
The issues is when they are in the table they are considered data, not
function pointers, by C's abstract machine.
From my source code when I ran into the issue. The nasty double cast
is needed to make the warning go away.:
/*
* You may not even convert a void * to a function
* pointer by explicit casting (6.3.2.3|1).
*
* C's abstract machine does not assume that code and
* data are addressed the same way, so as far as C is
* concerned function pointers and data pointers have
* nothing to do with each other (they could have
* different widths).
*/
static uint8_t (*state_function_ptr)( uint8_t ); /* Pointer to
function to execute when selected from the menu */
state_function_ptr = (uint8_t (*)(uint8_t))
PGM_READ_WORD( menu_state[current_state_u8].FunctionPointer );
if( NULL != state_function_ptr )
{
next_state_u8 = state_function_ptr( STATE_CHANGE );
/* Execute Function. It will return its current state to stay in this
state, or a new state for next time */
}