This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Compiler/TMS570LS20216: beginner STL & string

Part Number: TMS570LS20216
Other Parts Discussed in Thread: HALCOGEN

Tool/software: TI C/C++ Compiler

Hi all,

I'm struggling using C++ and STL. I'm new using SLT on embeddedplatforms.

My first try is just using string. I compiled a small main.cpp:

#include <string>

void app_main(void) {

std::string line;

 line = ">Hallo\n";

 line += " Welt, wie geht's?!\n";


Everything compiles well, but "lin" contains no meaningful data after the first assignment and the program crushes executing "+=".

I traced it down to some Location in the STL lib ... but I think I'm missing something?!

Can anyone help?

Bet regards

  • I presume you use the TI ARM compiler.

    My guess is you don't have enough stack or heap.  Just as an experiment, make the stack and the heap as large as you can.  Change the linker options --stack=size and --heap=size.

    Thanks and regards,


  • Hi George,

    thanks for the hint.

    Yes, I'm using the TI ARM Tools within CCSv7 as latest download from the Website.

    I increased stack & heap to 0x2000 (was 0x800 as default)  but git the same beaviour.

    I stepped in and found the call of malloc in "new_.cpp" (line 51) as a cause ... but I think I did something wrong - do not know what.

    To be more specific on my setting:

    # I'm using the TMS570LS20 USB board

    # I did several Tests just using C - worked all perfect (e.g. I could make a Connection via Serial and command my program to switch LEDs using a terminal program on my host)

    # now I set up a new project without main - generated the HAL with HalCoGen and inserted my own <app_main()>

    # my own main looks like this:

    # everything builds well

    # stepping through the programm with F6 does not return from line 17

    # stopping the programm shows the following:

    Any idea?

    Best regards

  • [ SORRY - my pictures went away - they were visible in the rich text editor ]

    app_main.cpp (new line numbering!)

    01 #include "app_main.hpp"
    02 #include <string>

    03 void app_main(void)
    04 {
    05     std::string line;
    06     line = "Hello";
    07    if (line=="Hello") {
    08        line += " World, how are you?\n";
    09    }
    10    while (true) ;
    11 }

    The program steps until line 08. On executing line 08 the program crushes as described.

  • All of the <string> operations are well tested before releasing the compiler.  That is why I continue to focus on a configuration error as the source of the problem.

    I am not familiar with HalCoGen.  Does it support C++?  Or just C?  If it does support C++, are special configuration steps required?  Consider starting a new thread in the Hercules device forum.  Or, if you prefer, I can move this thread into that forum.

    Thanks and regards,


  • Hi George,

    yes, I pretty much assume the fault is on my side - but where?
    I did some more tests and found that always with adding the 16th character the program crushes.

    What shall I provide (and how) to get some more hints?
    Am I the only one using std::string?
    Can someone provide a project that works fine so I can reproduce and inspect that?

    Best regards
  • Hi All,

    as George assumed: there was a configuration error!
    For some reason my HalCoGen did not generate the .sysmem entry. As soon as I added it, everything worked well.

    But why does this result in an error when using strings longer than 15 characters?

    Best regards
  • user4921928 said:
    Hi All,

    But why does this result in an error when using strings longer than 15 characters?

    To answer that question: most string implementations use an optimization where short strings are stored within the string object to avoid heap allocations. Storage on the heap is requested only if the string grows too large. This is most likely why everything works until you enter the 16th character (which most likely is the 17th character because _probably_ string includes a null termination to facilitate implementation of c_str())