[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: |
Georg-Johann Lay |
Subject: |
Re: [avr-gcc-list] Some issues with array of pointers to functions |
Date: |
Mon, 16 Jun 2014 11:49:28 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux i686; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 |
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