AnsweredAssumed Answered

char array initialization and truncation anomaly

Question asked by snoopy on May 8, 2013
Latest reply on May 10, 2013 by snoopy

Hello

 

I struck this weird anomaly using the STL string container. Building up a string by appending characters to it would truncate after the 128 th character and lose any additional characters. I thought the problem was with string container but then I back tracked a bit and found the problem can occur by initializing a character pointer with a null terminated string array.

 

For example try this

 

char *message="123457890123457890123457890123457890123457890123457890123457890123457890123457890123457890123457890123457890";

 

and watching the assignment in VDSP the last two characters ("90") are knocked off the end.

 

same thing happens with the string container

 

string message="123457890123457890123457890123457890123457890123457890123457890123457890123457890123457890123457890123457890";

 

but assigning it to a character array it appears to allocate the correct amount of memory with no truncation

 

char message[]="123457890123457890123457890123457890123457890123457890123457890123457890123457890123457890123457890123457890";

 

I am using Visual DSP 5 update 10.1 on a custom board with a ADSP-21489. The problem also shows up in the simulator.

 

regards

david

Outcomes