Hi Guys
I am facing a very strange problem related to the strlen inbuilt function in the keil C51.
I wrote few functions as follows:
Function 1 :
void ModMasterData(uChar *,uChar *,uChar,struct Master *);
Function 2 :
void ModFrameGenerator(struct Master *);
the typedef definition for the uChar is :
typedef unsigned char uChar;
What I have done is that I am pasing the source string defined as
code char *STestString = "Hello";
to the function ModMasterData as the first argument and also the strlen of that string as the third argument like this:
ModMasterData(STestString,&Command,strlen(STestString),&MasterBuf);
After that the ModFrameGenerator function is called which concatenates all the contents into a single Frame or array of size 25.
But what I seen by continuously monitoring the array over the Uart that it behaves correctly upto 15 or 20 rounds of data that is thrown over the Uart and after that start missing the data string in the array.
The data that should come is as follows:
9G5Hello6
But I got in this format
9G<00>$<00><00><00><00>
after 30-40 cycles of proper throwing of data over the Uart.
My question is that how can pointer or any function like strlen can start malfunctioning in between the flow of code, because in the first case it behaves correctly and than all of sudden it start throwing the garbage value.
Frankly it's more likely that the pointer, the content it points too, or the parameter passed to strlen() are getting screwed up.
You'll need to debug and analyze the code more thoroughly.
You could code your own strlen() equivalent easily and test that, instrument it or add asserts as desired.
Parameters are often passed as registers or on the stack, the C51 compiler tends to make the code look like a dogs breakfast as it shuffles and rearranges things. Look at optimization settings, adjust
Hi West
You are right............
as I debugged the code more deep I got that the pointer of the string which I am passing as the argument to my function is getting corrupted (by corrupted I mean that it starts pointing to some other location anyhow during runtime of the program).
It's very unusual thing that I have seen so far, actually west I want to know about the use of pointer in the keil C51 compiler in detail ( however I have gone through the documentation and the help file of the keil) but what they teach there are not enough, I think , for the proper use of the pointer in the Keil C51.
Also can you please tell me where I can get the details about the optimization policy of the keil C51 compiler.
There is nothing in the help file in this regard.
Thanks
Piyush Pandey