这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界» 论坛首页» 综合技术» 基础知识» ICCAvr,Bug ICCAvr的Bug(附测试代码)???请大虾们出招...

共3条 1/1 1 跳转至

ICCAvr,Bug ICCAvr的Bug(附测试代码)???请大虾们出招...

院士
2006-09-17 18:14:16 打赏
ICCAvr,Bug ICCAvr的Bug(附测试代码)???请大虾们出招...



关键词: ICCAvr 测试 代码 大虾 出招

院士
2006-12-22 22:43:00 打赏
2楼
问 /**********测试代码*********************/
#define CHANGE 1

unsigned char i;

#if CHANGE
void dump(void)
{
if(i>0) i++;
}
#endif

void test(void*p)
{
i=1;
p=p;

}

unsigned char argu_test(void (*ppdata)(void*pp),unsigned char m)
{
unsigned int p,t;
t=(unsigned int)(*ppdata);
p=(unsigned int)ppdata;
return ++m;
}

void main(void)
{
unsigned char j=0;
while(1)
{
if(argu_test(test,3)) continue;
j++;
}
}

很显然,改变CHANGE的宏定义就可以改变test函数的首地止
我得测试结果

编译器 CHANGE的值 p值 t值
Turbo C 2.0 1 522 522
0 506 506
KeilC 7.01 1 0x3c 0x3c
0 0x32 0x32
ICCAVR6.28 1 0x54 0x54
0 0x54 0x54

从反汇编来看,KeilC里的值和其地址值是对应的,TurboC没看,ICC中的值和其首地址明显不对应(无论首地址是多少,p、t值都是常量0x0054)!
请大虾们用自己的ICC测试一下,看看是不是只是我的编译器有问题,谢谢!


1: 没人有ICC吗?把程序复制进去运行一下好像不麻烦吧? 2: ICC AVRBUG? 3: ICC AVRBUG?CHANGE=1,test=0x38, CHANGE=0,test=0x2e,使用 AVRSTUDIO3.56用模拟运行方式查看. 4: zhaohuoc兄:你查看的是test的值!
这个值是正确的
我说的是在函数调用时,这个值不会被正确的传递!◎

不信老兄再运行一次,看看 p的值和 t 的值! 5: 我发信给imagecraft,问题解决了但不理解为什么他们要把编译器做成这样。TC是直接传送地址的。不知道到底TC和标准C兼容还是ICC.

When you pass an address of a function, ICC AVRcreates a word in the
flash
that CONTAINS the address of the function, and uses the address of that
label as the value, e.g.

_PF_test::
.word `_test

...
In C, when you say
void test();
...

argu_test(test,...

instead of passing address of test, we would pass the address the of
PF_test. It all works right because when you call a function pointer,
the
compiler does the indirect fetching for you, so it works right.



6: 音乐乐乐 你试试下面这一段,
unsigned char argu_test(void (*ppdata)(void*pp),unsigned char m)
{
unsigned int p,t;
t=(unsigned int)(*(unsigned char *)ppdata);
p=(unsigned int)ppdata;
return ++m;
}

按照你的代码, AVRSTUDIO算出的P=T,P一段的代码干脆给优化了,好象并没有把ppdata当做指针,我还是不明白你这段代码到底想说明写什么 7: 我想说明再其他编译器传递的是函数首地址而ICC传递的是一个指向函数首地址的指针 8: 明白ICC传递的是一个指向函数首地址的指针的指针

高工
2022-08-20 15:41:45 打赏
3楼

感谢分享


共3条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册]