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/TMS320F28379D: Compiler support for variable length arrays

Part Number: TMS320F28379D

Tool/software: TI C/C++ Compiler

Does the C28x C compiler support variable length arrays, and if so is there anything I should be careful of?

For example, this...

void myFunc(uint16_t a)

{

    uint16_t i;

    float32_t myArr[a];

 

    for (i=0; i<a; i++)

    {

        myArr[i] = 0;

    }

}

 

main()

{

    myFunc(10);

...ends up in an infinite loop in exit.c.  I am building with C99 and relaxed ANSI, and .sysmem is 0x400 in length.  Does anything come to mind?

  • Yes, the TI compiler does support VLA in C99 mode. It does so by using dynamic allocation, so you are right to check .sysmem. I can't see anything wrong with the code you post, and when I run it myself, it runs fine. Perhaps your program needs more that 0x400 for the heap?

    Are you running this program under CCS? The normal flow for a program which reaches exit is that exit calls abort, which has an infinite loop. CCS sets a breakpoint at a special label in this infinite loop; if you don't set a breakpoint there, the program will execute the infinite loop. Are you sure this breakpoint is still there when you run the program? It is possible for some setups that you can only have a limited number of breakpoints.
  • Richard Poley said:
    I am building with C99 and relaxed ANSI, and .sysmem is 0x400 in length.

    The lib\src\vla_alloc.cpp source file in the run time library is used to allocate / deallocate variable length arrays. On the first attempt to allocate a VLA vla_alloc.cpp needs to allocate the VLA storage pool which as of TI compiler v16.9.5 requires 1500 words.

    Therefore, a system of length 0x400 is insufficient to allocate the VLA storage pool, and exit() will be called on the first attempt to allocate a VLA since vla_alloc.cpp fails to allocate the VLA storage pool. i.e. increase the size of sysmem to allow space for the 1500 words for the VLA storage pool as well as the VLA arrays.

  • Heap size was the problem.  Thanks very much for the help.

    Regards,

    Richard