|
|
View previous topic :: View next topic |
Author |
Message |
/dev/human
Joined: 01 Sep 2008 Posts: 19 Location: Earth / Europe / Germany
|
Strange code results using an array [solved] |
Posted: Wed Apr 22, 2009 11:03 pm |
|
|
Hi All
I programmed a simple piece of code to handle a simple stack.
Code: |
float32 TemppH;
float32 TempT;
int loop;
StackHnd (0, 0, Clear);
for (loop = 0; loop < 20; loop++) {
TempT = loop+1;
TemppH = loop+1;
StackHnd (&TemppH, &TempT, Push);
}
int StackHnd (float32* pH, float32* T, int Cmd) {
static int StackPntr = 0;
float32 phStack [Stacksize];
float32 TStack [Stacksize];
switch (Cmd) {
case Clear:
for (StackPntr = 0; StackPntr < Stacksize; StackPntr++) {
pHStack [StackPntr] = 0.0;
TStack [StackPntr] = 0.0;
}
break;
case Push:
for (StackPntr = 1; StackPntr < Stacksize; StackPntr++) { // Top of stack is "StackSize", bottom is 0
phStack [StackPntr -1] = phStack [StackPntr]; // Push all pH values down
TStack [StackPntr -1] = TStack [StackPntr]; // Push all temp values down
}
pHStack [StackSize-1] = *pH; // Put actual value on top
TStack [StackSize-1] = *T; // Put actual value on top
break;
case Calc:
break;
default:
}
return 0;
}
|
This piece does not seem to difficult to me but checking the stack I do see:
Quote: |
pHStack: (2.172,3.000,4.000,5.000,6.000,7.000,8.000,9.000,10.000,11.000)
TStack: (2.000,3.000,4.000,5.000,6.000,7.000,8.000,9.000,10.000,11.000)
|
Any ideas for pHStack [0]
Thanks in advance! _________________ Never check your brain at the door!
Last edited by /dev/human on Thu Apr 23, 2009 10:51 pm; edited 1 time in total |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Wed Apr 22, 2009 11:30 pm |
|
|
The problem could be traced, if you had provided complete code, but you preferred not to do.
I guess, that phStack is overwritten, cause it's not declared static. Can be easily checked in the projects *.sym file. Generally, the compiler can be expected (respectively is required) to overlay phStack with other variables outside the function, to save RAM space. |
|
|
/dev/human
Joined: 01 Sep 2008 Posts: 19 Location: Earth / Europe / Germany
|
|
Posted: Thu Apr 23, 2009 10:51 pm |
|
|
Thanks, stupidly blind. The ram space was actually used by another var.
... and yeah, I actually preferred not to send the remaining about 564 lines of code. _________________ Never check your brain at the door! |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|