hi i have a problem with adl_memGet function. It confuses the string. Here is my code
void fo1()
{
char * myVar = adl_memGet(10);
int i;
for(i=0;i<sizeof(myvar);i++) // initialize my var
myVar[i]=’\0’;
strcpy(myVar,“123456”);
adl_SendResponse(myVar); // write myVar on the screen . it writes 123456 thats correct
adl_memRelease();
}
void fo2()
{
char * myVar = adl_memGet(10);
int i;
for(i=0;i<sizeof(myvar);i++) // initialize my var
myVar[i]=’\0’;
strcpy(myVar,“ABC”);
adl_SendResponse(myVar); // write myVar on the screen . it writes ABC456 thats incorrect. what the hell is this
adl_memRelease();
}
it also confuses the strcat oparations. How can i reduce this error? if i use static allocation i need more and more space in ram.
The sizeof(myVar) call will only return the size of the variable (i.e. the size of a char pointer), not the size of the memory referenced by that variable. You’re lucky that you’re not scribbling over other variables when you do your for() loop.
You should also look at using the Wavecom defined data types (e.g. s16, ascii, etc) as the code is being cross-compiled to an ARM processor, and the size of an int/double/long etc may not be what you are used to. Same goes with using the wavecom versions of the string (strcpy etc) functions. I know that these functions are simply re-definitions of the existing functions, but this may not always be the case…
thank you very much for your fast reply . also i tried fast and got the result correctly.
the problem was with me as you said. i thought that sizeof(char)=1 so no need to say adl_memGet(sizeof(char)*varSize) .
i wrote only adl_memGet(varSize)
and the second mistake was with for loop. i tought that sizeof(myVar) returns the varSize. Now i changed sizeof(myVar) to varSize.
Now no problems can be seen now thank you very much again