memset not working for pointer when compiled to flash memory

Dear all,

This thread is related to the one I posted earlier, on 29th-october.
Further trial and error narrowed the problem to the next:

I’m struggling with a pointer related problem:

Char *Message[10], text[1];
memset(*Message, 0, 10);
memset(text, 0 , 1);

Compiled to RAM: OK: memset initializes the variables *Message and text to “”.

Compiled to FLASH: only the variable text is initiaized to “”.

It seems that I can’t write to *Message when program is compiled to FLASH, even not with memset. Writing to the variable text is no problem.

Can someone explain this behavior to me / tell me what I can do to get it working nnormally?

Unfortunately I have to use pointers since I have to use strcat, otherwise it wouldn’t be a problem.

Thanks again for your attention.
Noël Willems

Noël,

the statement “char *Message[10]”
defines message as an array of 10 pointers to char. I believe what you want is “char Message[10]” which is an array of 10 chars.

memset(*Message, 0, 10);

is the equivelant of

memset(Message[0], 0, 10);

which means: fill the 10 bytes pointed to by the pointer in Message[0] with 0. Depending on what has been placed in Message[0] this could end up writing to anywhere in memory.

Regards,
Peter

Hello Peter,

Thanks for your reply!
You’re right: Initially I wanted

“char Message[10];” an array of 10 chars.

But I would like to use “Message = strcat(Message, text);” which doesn’t work unless the left side of “=” is a pointer variable. That’s why I went to “char *Message[10];” which worked when compiled to RAM.

I keep finding it strange that it works perfect if compiled to RAM. It doesn’t work if compiled to FLASH.

The same behavior occurs if I write a some trial code with “int” instead of “char”:

int i, *j;
memset(i, 0, 1);
memset(*j, 0, 1);

works fine in RAM, in FLASH i is initialized, *j is not.

PS: Dynamic C 8.61, BL2110 board.

Kind regards,
Noël

Hi Noël,

There is normally no reason to store the return value from strcat as the string has been copied to where you need it and most of the time you just ignore the return value. It is normally only used if strcat appears in complicated expression and even there you have to be really careful about the order of evaluation.

Regards,
Peter