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

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

Re: [avr-gcc-list] Some issues with array of pointers to functions


From: Bob Paddock
Subject: Re: [avr-gcc-list] Some issues with array of pointers to functions
Date: Fri, 13 Jun 2014 08:25:29 -0400

> __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 */
                 }



reply via email to

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