|
|
View previous topic :: View next topic |
Author |
Message |
rohit Guest
|
issue in strtok.save |
Posted: Sat Mar 21, 2009 3:09 am |
|
|
Hi all,
I am a new to PCH compiler.
I am using pic18F458 processor.
I am creating a motor control application.
I am using a number of global variables in my code
Somehow my variable for "Set speed" which too is a global variable is getting corrupted.
I looked into the symbol file and found that just above the "Set speed" variable there is a variable called strtok. Save of 1 byte. I have not declared this variable, I looked in to the code and found there is a function defined in string.h file called as strtok() and it defines a static pointer "save". May be the case that this pointer is overwriting my data.
But I am not using strtok(), strcpy(), or strlen(), sprintf() functions.
I am wondering from where this variable is getting generated.
Has anybody else faced such an issue ?
Thanks and regards.
Rohit
India |
|
|
Ttelmah Guest
|
|
Posted: Sat Mar 21, 2009 4:23 am |
|
|
It is very unlikely to be this pointer.
First, other people would have noted a problem like this.
Second though, is that pointers themseleves are fixed size objects, so are unlikely to result in memory overflow problems. It is things _addressed_ by pointers (or arrays), that are the likely problems.
More likely, that there is something further 'up' (or down) the memory map, that is being addressed _by_ a pointer, and is resulting in the overflow.
Now, you may well be using a function that calls strtok. If you are performing any form of search for a character in a string, or comparing strings, then string functions are probably being called.
First thing to do, is add a diagnostic test. Add a couple of new dummy variables. On in front of your set_speed variable, and one after. Use comething like:
char dummy1[] = "ABC";
//define setspeed here
char dummy2[] ="DEF";
Then define a test macro, something like:
#define test_dummies(x) if (dummy1[0]!='A' || dummy2[3]!='\n') alert(x)
and have a function 'alert' that prints the number passed. Scatter 'test_dummies' entries through your code, with different numbers.
Once 'alert' is called, you will know roughly where in the code, the change takes place - between the last 'alert' call, and the one that triggers. Hopefully you can then narrow it down.
You can also print the values in dummy1, and dummy2, to see which direction the problem is coming from. The values may also shed some light on what is happening.
Best Wishes |
|
|
rohitd Guest
|
re |
Posted: Sun Mar 22, 2009 9:05 am |
|
|
Thanks Ttelmah,
For the promt reply, I will implement your suggestions , and get back with the results.
Thanks again for the reply
Regards
Rohit
(India) |
|
|
|
|
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
|