Problems returning pointers in optimized code

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Problems returning pointers in optimized code

1,199件の閲覧回数
cws
Contributor I
I was trying to return a pointer from a function and was getting some strange results.

char *LookUpPtr(int selector)
{
char *addr;

addr = /* some math */
return addr;
}

I turned Optimizations Off and it started to work. Anyone know how to fix this?


I was able to pass the pointer via:

void LookUpPtr(int selector, char **ptr)
{
char *addr;

addr = /* some math */
*ptr = addr;
}


I’m using CodeWarrior Development Studio for ColdFire Architectures Version 6.3 (Preview Release) and targeting the MCF52233 Coldfire.

Thanks,
Curt
ラベル(1)
タグ(1)
0 件の賞賛
1 返信

418件の閲覧回数
KenJohnson
Contributor II
Look at the assembly code generated by your function with optimization enabled. Note whether it is returning the pointer return value in d0 or a0. Look at the assembly code generated by the calling function with optimization enabled. Is it expecting the pointer return value in d0 or a0? If the two don't agree, check that the pointers_in_d0 pragma is being used correctly.
0 件の賞賛