Am 06/13/2014 12:06 PM, schrieb Royce Pereira:
Hi all,

Continuing with the latest avr-gcc, and playing with the new '__flash'
qualifier, I'm facing some new warnings, not seen before.

I have this:
//===================
void func1(void)
    {
       //........
    }
//===================
void func2(void)
    {
       //........
    }
//===================
void func3(void)
    {
       //........
    }
//===================

__flash void (*funcArray[])(void) = { func1, func2, func3 } ;

//====================
unsigned char funcNo;

int main(void)
     {
        //...code that sets 'funcNo'

        (funcArray[funcNo])() ;  //call the desired function from the array.

        return 0 ;
     }
//============================
/*
No error is thrown and the code runs fine on the target board too.

But I get the following warnings, and I don't know why :

warning: initialization from incompatible pointer type [enabled by default]
{ func1, func2, func3 } ;
   ^

warning: (near initialization for 'funcArray[0]') [enabled by default]
warning: initialization from incompatible pointer type [enabled by default]
warning: (near initialization for 'funcArray[1]') [enabled by default]
warning: initialization from incompatible pointer type [enabled by default]
warning: (near initialization for 'funcArray[2]') [enabled by default]
warning: initialization from incompatible pointer type [enabled by default]

  In function 'main':
warning: function with qualified void return type called [enabled by default]
     (funcArray[funcNo])() ;

Your functions are of prototype "void (*)(void)", not of "void (*)()".

And the return type is "void", not "__flash void"; avr-gcc throws a diagnostic on this.

If you want to put the array in flash, then put funcArray in flash:

void func1 (void) {}
void func2 (void) {}
void func3 (void) {}

void (* const __flash funcArray[])(void) = { func1, func2, func3 } ;

void run (unsigned char funcNo)
{
    funcArray[funcNo] ();
}


Johann


_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
https://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Reply via email to