I have some compilator errors due to pointer of function
void MyFunct(void)
{
.....
.....
.....
}
void main(void)
{
void (*MyPtrfunc) ();
MyPtrFunct = &MyFunct;
MyPtrFunct = MyPtrFunct - OffSetSW //Compilator error desciption : Error C1829 : + - incompatible Type
MyPtrFunct();
}
I already use this kind of declaration with another compilator, and i have no issue!!!
Do you have any about idea about my issue?
For you comprehension : Before run this command line, i rewrite Myfunction in spectific section in flash.
In fact, i try run a function place @ specific adress. This specific adress is Default adress (cofigured by emulator) - 0x1800.
Thanks
David
I very much doubt this is true. Could you please cite the ISO standard?
It is however indeed true that you can't use sizeof on function pointers.
ANSI-C does not support pointer arithmetic for function pointers, more concretely ANSI-C defines pointer arithmetic for object type pointers only, here the definition for the addition:
And object types are distinct types form function types:
So in other words, ANSI-C does not support pointer arithmetic on function pointers.
Daniel
PS: Snippets above copied from some C standard draft found on the web.
Message Edited by CompilerGuru on 2008-11-12 03:24 PM
The warning means that the code isn't legal C but that the compiler has made a non-standard extension to allow it. So the code will be non-portable.
The quick & dirty way around it is to cast both pointers to integer, then substract, then cast the result back to a function pointer.