Problems returning pointers in optimized code

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Problems returning pointers in optimized code

1,195 Views
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
Labels (1)
0 Kudos
1 Reply

414 Views
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 Kudos