We have C compilers version 4.03 and was wondering if any compiler versions after this has this problem. We have a function array set up to point to functions that return a structure. We have found that the stack is not cleaned up after returning from a function on this array. The code would be something like this: typedef struct { int value; boolean status; } struct_Results; typedef struct_Results (*funcptr)(void); const funcptr functarray[] = { GetFirstValue, GetSecondValue, GetThirdValue, GetFourthValue }; Then in the function: int loop; struct_Results results[4]; for ( loop = 0; loop < 4; loop++ ) { results[loop] = functarray[loop]; } The stack is off coming back from any one of these calls and the offset is times 4 since this function array is called 4 times. Has anyone else experienced this problem? Thanks, Rick Brown
Compiled your code with v4.26a, saw no problems. Which stack pointer is off: system stack pointer SP or user stack pointer R0? In your code sample, you didn't show what the GetNthValue functions do. Could they do weird things like SP+=2 or ADD R0,#2? - mike
You're assigning the function pointers themselves, not the structs you would get if you call those functions:
results[loop] = functarray[loop];
results[loop] = functarray[loop]();
I miswrote my code here. The array in my code does have ) at the end. RO is the one that is off.