|
From: | Thomas Buchta |
Subject: | Re: [avr-gcc-list] calling function pointers via pointers ? |
Date: | Wed, 28 Sep 2005 16:16:59 +0200 |
User-agent: | Opera M2/8.0 (Win32, build 7561) |
Hi Lars! In many of my applications I use a called function pointer within an array in program memory like such example code: typedef INT8S (*PF_KEYFUNCTION) (MAIN_SYSTEM_STATE_T *ptrSystemState); PF_KEYFUNCTION PROGMEM mainKeyFunction[N_MAX_KEYNUMBER][N_KEY_EVENTS] = {/* Key Event -> KEY_NOT_ACTIVE KEY_ACTIVE KEY_LONG_ACTIVE KEY_VERY_LONG_ACTIVE KEY_RELEASED */
/* Key *//* 0 KEY_02 */ { no_function, mixMatrixNode, gainDelaySet, no_function, mixMatrixNode_update_req, },
.../* 31 KEY_31 */ { no_function, mixMatrixNode, gainDelaySet, no_function, mixMatrixNode_update_req, }
}; void foo(void) { INT8S (*ptrF_KeyFunction) (MAIN_SYSTEM_STATE_T *ptrSystemState); .... /* get copy of function pointer */ memcpy_P((void*)&ptrF_KeyFunction, (PGM_VOID_P)&mainKeyFunction[keyNumber][action], 2 ); /* call the function */ ptrF_KeyFunction (ptrMSystemState); ... }
* Vincent Trouilliez <address@hidden> [2005-09-28 14:16]:Another pointer problem again, oops... I need pointers to functions in my project. Using the great on-line resource http://www.eskimo.com/~scs/C-faq/q4.12.html which someone on here mentioned recently, I got the basics working. But my actual case at hand is a bit trickier and I am lost again (okay, doesn't take much to loose myself I admit ;-). Problem: my function pointers are in an array, within a structure, which itself is accessed via pointers... oh dear.Just do it step by step, at least for first tries use temporary variables - you can avoid those after you understood what to do ;) - Dereference the pointer to the struct. This gives you a struct. - Select the field from the struct. This gives you an array. - Select the entry from the array. This gives you a function pointer. - Dereference the function pointer and call the function. Done. _______________________________________________ AVR-GCC-list mailing list address@hidden http://lists.nongnu.org/mailman/listinfo/avr-gcc-list
-- Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
[Prev in Thread] | Current Thread | [Next in Thread] |