You cannot initialize an array with a static storage duration with a mutable object.
Either declare an array as
void (*stateTable2[]) (void) = { function1, function2 };
or move the ad
void (*stateTable2[]) (void) = {function1,fptr};
inside main, making the array as an array with automatic storage duration.
Here is a demo program.
#include <stdio.h>
void function1 (void)
{
printf( "Hello " );
}
void function2 (void)
{
puts( "World!" );
}
void (*fptr)(void) = function2;
int main(void)
{
void ( *stateTable2[] ) (void) = { function1, fptr };
void(*fp)(void) = fptr;
fp();
for ( size_t i = 0; i < sizeof( stateTable2 ) / sizeof( *stateTable2 ); i++ )
{
stateTable2[i]();
}
return 0;
}
His conclusion
World!
Hello World!