| Details | Message |
|---|
Read-Only Author maxwell hero0765 Posted 1-Sep-2010 04:46 GMT Toolset C51 |  about error C212 in keilC51 maxwell hero0765 hi: when I compile the below code ,the keil51 emergered a error : error C212: indirect call: parameters do not fit within registers . source code: typedef struct NODE{ struct NODE *link; int value; }NODE; int compare_ints(void const *a,void const *b) { if(*(int *)a == *(int *)b) return 0; else return 1; } NODE * search_list(NODE *node,void const *value, int(*compare)(void const *,void const *)) { while(node != NULL ){ if(compare(&node->value,value)==0)//error point break; node = node -> link; } return node; } int main() { NODE *cur,*root; int value; cur = search_list(root,&value,compare_ints); } I can find where the error happen ,I mark with"error point" in the code. the compare() function pointer can not be filled in parameters,or the compile gives an alarm. I don't know why. |
|
Read-Only Author Andy Neil Posted 1-Sep-2010 06:47 GMT Toolset C51 |  RE: I don't know why. Andy Neil Keil C51 has major issues with using function pointers: http://www.keil.com/appnotes/docs/apnt_129.asp http://www.keil.com/support/search.asp?SA=8051&KW=&DY=&PL=&Q=function+pointer&KB=ON&PM=ON&PG=1&PX=1&AV=ON Basically, the 8051 is not "just another processor" that you can program as you would a PC, etc. The 8051 architecture has some very specific optimisations that make it very good for some things, and very poor for others - and function pointer is one of those things to which it is not well suited! If function pointers really are essential to your application, then you should probably not be using an 8051 - at the very least, you need to study the issues very carefully! |
|
Read-Only Author J. Christoph Posted 1-Sep-2010 07:25 GMT Toolset C51 |  about error C212 in keilC51, just 'google' it J. Christoph Answer can be found quite easy: http://www.keil.com/support/docs/2066.htm So add reentrant to the function pointer definition: NODE * search_list (NODE *node, void const *value, int(*compare)(void const *,void const *) reentrant) And, by the way, never! exit your main() function! Use a while(1) loop, or similar thing. |
|
Read-Only Author Andy Neil Posted 1-Sep-2010 08:04 GMT Toolset C51 |  RE: add reentrant to the function pointer definition Andy Neil But do note that this will have a (significant) impact on performance. Again, you are fighting the specific features of the architecture here - consider whether the fight is really worth it, or a different architecture would be more appropriate... |
|
Read-Only Author erik Malund Posted 1-Sep-2010 12:02 GMT Toolset C51 |  RE: add reentrant to the function pointer definition erik Malund it is very well said previously in this thread Basically, the 8051 is not "just another processor" that you can program as you would a PC, etc. if you want to code for the '51 you WILL have to code "'51 C" not "C" I would state the above reoly this way consider whether the fight is really worth it, or a different software architecture would be more appropriate. Function pointers, for all practical purposes is a "convenience feature". Erik |
|
Read-Only Author Andy Neil Posted 1-Sep-2010 12:39 GMT Toolset None |  RE: Function pointers, for all practical purposes is a "convenience feature". Andy Neil In fact, writing anything in 'C' is a "convenience feature"! Function pointers are "inconvenient" to the 8051 architecture because of the nature of the 8051 architecture; in other architectures, it's no big deal - there is no (significant) penalty and, therefore, no reason not to take advantage of their convenience! |
|
Read-Only Author erik Malund Posted 1-Sep-2010 13:50 GMT Toolset None |  RE: Function pointers, for all practical purposes is a "convenience feature". erik Malund in other architectures, it's no big deal agreed. Ever so often we see that the "architecture ignorance", which for the PC is not a big deal, carries a heavy penalty in the smaller micros. it's been a while, but here it is again The '51 aint no PC Erik |
|