关于 keil C51 warning C182: Pointer to Different Objects 解决.
来源:互联网 发布:qq群淘宝客用什么软件 编辑:程序博客网 时间:2024/06/05 04:29
帮助文档里的解释是:
"Warning C182 : Pointer to Different Objects"
这里的警告一般都是犯的类型不匹配的错误, 例如int 型与int *类型互相赋值. 等等.
我这里犯的错误是, 我使用了函数指针, 而且参数超过了三个, 由于 keil 编译器的参数并不经过栈来传递参数, 超过三个就会报错或者警告.
按照帮助文档的解决方法, 要加 reentrant 关键字来告诉编译器对函数进行可重入和可递归处理.
例如我在结构体内的函数指针后面加入 reentrant 关键字, 如果要将某个函数赋值给这个函数指针, 那么这个函数在定义和声明的时候都要加入 reentrant 关键字.
具体如下:
unsigned char (* pFunc) (unsigned char *a, unsigned char *b, unsigned int len) reentrant;
声明时:
unsigned char Test_Reentrant_Fun(unsigned char *a, unsigned char *b, unsigned int len) reentrant;
定义时:
unsigned char Test_Reentrant_Fun(unsigned char *a, unsigned char *b, unsigned int len) reentrant{ // your code}
不然
pFunc = Test_Reentrant_Fun;
就会出现 C182 警告.
关于 reentrant function 可以参考 Cx51 帮助文档.
这里摘录一部分内容:
A reentrant function may be shared by several processes at the same time. When a reentrant function is executing, another process can interrupt the execution and then begin to execute that same reentrant function.
Normally, functions in Cx51 cannot be called recursively or in a fashion which causes reentrancy. The reason for this limitation is that function arguments and local variables are stored in fixed memory locations. Recursive calls to the function use the same memory locations. And, in this case, arguments and locals would get corrupted.
The reentrant function attribute allows you to declare functions that may be reentrant and, therefore, may be called recursively. For example:
int calc (char i, int b) reentrant { int x; x = table [i]; return (x * b);}
Reentrant functions can be called recursively and can be called simultaneously by two or more processes. Reentrant functions are often required in real-time applications or in situations where interrupt code and non-interrupt code must share a function.
- 关于 keil C51 warning C182: Pointer to Different Objects 解决.
- warning C182: pointer to different objects
- C51: WARNING 259 POINTER: DIFFERENT MSPACE
- warning: cast to pointer from integer of different size
- warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]错误
- warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
- LINUX下warning: cast from pointer to integer of different size问题
- !!!How to initialize pointer with new objects
- 关于keil c51里面的 printf 函数
- 关于用KEIL编写C51的注意事项
- 关于如何解决warning: assignment makes pointer from integer without a cast的警告
- keil中 如何解决warning L13:Recursive call to Function 及overlay解释
- 2.Different ways of Converting and Casting objects to different types of objects
- keil -- WARNING L15: MULTIPLE CALL TO SEGMENT
- keil c51 不能使用:Go to Definition of....的解决方法
- keil c51 不能使用:Go to Definition of....的解决方法
- Cannot send events to objects owned by a different thread
- Is the type of “pointer-to-member-function” different from “pointer-to-function”?
- 非常好的理解遗传算法的例子
- java文件和文件夹复制、删除、移动操作
- Oracle with语句的用法
- Nginx源码分析-事件循环
- 【转】iOS开源项目汇总
- 关于 keil C51 warning C182: Pointer to Different Objects 解决.
- 字符串转为float,int,double类型
- apache tomcat问题
- android文件下载大小和网络不一致(偏大)
- android RatingBar自定义图片
- 像计算机科学家一样思考python2 笔记 - 字典 Dictionary
- iOS eXosip2 osip2 编译
- 内核线程
- C/C++:函数的编译方式与调用约定以及extern “C”的使用