| ||||||||
Technical Support Support Resources Product Information | C51: PASSING PARAMETERS TO INDIRECTLY CALLED FUNCTIONSInformation in this article applies to:
SYMPTOMSI'm using function pointers and object-oriented programming techniques in my application. Most of the time my program works as expected. But when I try to pass several parameters to functions that are called via pointers, I get the following compiler error message: Error 212: Indirect call: Parameters do not fit within registers. The program example below demonstrates this:
void (*CallBack1) (void *, unsigned char);
void (*CallBack2) (void *, void *);
void (*CallBack3) (char, char, char);
void (*CallBack4) (char, char, char, char);
unsigned char c, d, e, f;
char *ptr;
void test (void) {
CallBack1 (ptr, c); // works
CallBack2 (ptr, ptr); // fails - C51 generates an error message
// indirect call: parameters do not fit within
registers */
CallBack3 (c, d, e); // works
CallBack4 (c, d, e, f); // fails - C51 generates an error message
// indirect call: parameters do not fit within
registers */
}
CAUSEUnlike most 16-bit and 32-bit microcontrollers, the 8051 is not a stack based architecture. When parameters do not fit into the CPU registers, the Keil Cx51 Compiler by default uses direct memory locations for parameter passing. This technique generates very efficient code but limits the parameters that can be passed to indirectly called functions. When parameters passed to a function via a function pointer will not fit into registers, the compiler cannot determine where in memory to place the parameters since the function is not known at call-time. RESOLUTIONThere are two ways to solve your programming problem.
MORE INFORMATION
SEE ALSO
FORUM THREADSThe following Discussion Forum threads may provide information related to this topic.
Last Reviewed: Friday, July 15, 2005 | |||||||
| ||||||||