error C212: indirect call: parameters do not fit within registers
来源:互联网 发布:网页设计需要美工吗 编辑:程序博客网 时间:2024/05/22 20:09
转自: http://www.keil.com/support/docs/2066.htm
Information in this article applies to:
- C51 All Versions
- Cx51 All Versions
SYMPTOMS
I'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 withinregisters */ CallBack3 (c, d, e); // works CallBack4 (c, d, e, f); // fails - C51 generates an error message // indirect call: parameters do not fit withinregisters */}
CAUSE
Unlike 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.
RESOLUTION
There are two ways to solve your programming problem.
- Create reentrant functions using the reentrant function attribute. The compiler simulates a stack-based architecture which makes it possible to pass a virtually unlimited number of parameters to indirectly called functions. For example:
void (*CallBack1) (void *, unsigned char);void (*CallBack2) (void *, void *) reentrant;void (*CallBack3) (char, char, char);void (*CallBack4) (char, char, char, char) reentrant;unsigned char c, d, e, f; char *ptr;void test (void) { CallBack1 (ptr, c); // works CallBack2 (ptr, ptr); // works, but now the function that gets called // need to have the reentrant attribute CallBack3 (c, d, e); // works CallBack4 (c, d, e, f); // works, but now the function that gets called // need to have the reentrant attribute}
- Limit the number and types of parameters so that they all fit into CPU registers. Do this when you need utmost performance or when program size is critical. For example:
void (*CallBack1) (void *, unsigned char);void (*CallBack2) (void xdata *, void xdata *);void (*CallBack3) (char, char, char);void (*CallBack4) (char, char, int);unsigned char c, d, e, f; char xdata *ptr;void test (void) { CallBack1 (ptr, c); // works CallBack2 (ptr, ptr); // works, but pointers are memory typed now CallBack3 (c, d, e); // works CallBack4 (c, d, e | (f<<8)); // works, but two chars are packed into // one int parameter}
The parameter passing method is described in the C51/Cx51 Compiler User's Guide. Refer to this to determine how to change your function parameters to fit into registers.
MORE INFORMATION
- Refer to Function Parameters in the Cx51 User's Guide.
- Refer to Application Note 129: Function Pointers in C51 for a complete discussion of all the ramifications of using function pointers with the C51 compiler.
- error C212: indirect call: parameters do not fit within registers
- Angular2 AOT编译出现Supplied parameters do not match any signature of call target
- supplied parameters do not match any signature of call target html
- C51 Parameters and Registers
- Error converting document: task did not complete within timeout解决方法
- Ionic3 error: could not find gradle wrapper within android sdk.
- 移植ucos出現 Error: registers may not be the same -- `strexh r3,r2,[r3]' 處理
- Error: The spatial references do not match
- error C2660: 'Open' : function does not take 12 parameters
- error C2660: 'SaveAs' : function does not take 11 parameters
- error C2660: 'new' : function does not take 3 parameters
- error C2660: 'new' : function does not take 3 parameters
- error C2660: 'new' : function does not take 3 parameters
- error C2660: ‘Create’ : function does not take 2 parameters
- insmod: ERROR: could not insert module module.ko: Invalid parameters
- 【强烈推荐】Zend_xmlrpc构建webservice服务器接口教程 Calling parameters do not match signature
- error C4996: 'std::_Copy_impl': Function call with parameters that may be unsafe
- C++:error C4996: 'std::_Uninitialized_copy0': Function call with parameters that may be unsafe
- 数据预处理
- 如何在S3C2440上linux操作系统下将串口的波特率提高以致921600
- shell---数组的使用
- Android(Java):切换3g提醒
- android:自定义layout动态改变view位置和大小
- error C212: indirect call: parameters do not fit within registers
- web.xml 加载顺序
- 微信公众平台开发[7]-开发模式-高级功能-主动发消息
- android 通过通过javaemail 来发送email 无需系统支持,无需配置
- HDFS中的通信协议
- 变量声明和定义的区别
- 微信公众平台开发[8]-开发模式-高级功能-获取关注用户的信息
- 监听Activity进入后台(最小化),并根据时间判断是否超时,此解决办法可用于超时重登陆
- bean的作用域