Posted
by: 邱小新
at 下午4:02
in
SDCC
函數指標當成參數傳遞
- 參數宣告
void PassPtr(int (*pt2Func)(int));
void PassPtr(int (*pt2Func)(int, char, char) __reentrant);
- 程式範例
int DoIt(float a, char b, char c) __reentrant
{
printf("DoIt\n");
return a+b+c;
}
int DoMore(float a, char b, char c) __reentrant
{
printf("DoMore\n");
return a-b+c;
}
void PassPtr(int (*pt2Func)(float, char, char) __reentrant)
{
int result = (*pt2Func)(12, 'a', 'b');
printf("%d\n", result);
}
void main()
{
printf("Executing 'Pass_A_Function_Pointer'\n");
PassPtr(&DoIt);
PassPtr(&DoMore);
}
張貼留言