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.

CCS/MSP430FR5969: What is causing the code to exit main when trying to create an array during run time?

Part Number: MSP430FR5969


Tool/software: Code Composer Studio

Hi,

I wrote the following piece of code today on CCS:

#include <msp430.h>

void Call_This_Func(int len)
{
int array[len];
array[0] = {0};//Code exits this function abruptly and goes to infinite for loop in exit.c file after alloc.cpp file
}

void main()
{
Call_This_Func(10);
while(1);
}

The code abruptly exits the function and main jumps straight to exit.c file (after going in alloc.cpp file).

I understand that this might be due to allocation issues but couldn't understand why it should be a run time error if value passed is legit?

Could someone explain why this is happening?

Also, I would like to have some expert opinions on: is this a acceptable way to create arrays ? If not, then what may be the a better approach?

  • That's not quite valid syntax; I'll assume you wrote "array[0] = 0;" without the curly braces.

    What you've got is a variable-length array. This feature requires special run-time handling when the function is entered. The TI compiler implements this by using dynamic allocation from the heap. Make sure you have a generous heap defined, perhaps 100 bytes just to test. If that doesn't resolve the problem, we'll need to see a complete test case. Please show us your complete command line options, a compilable test case, and the complete linker command file. It might be simpler to zip up your entire project and post that.
  • Hi @Archaeologist, Sorry for such a late reply. If this is a syntax error, then shouldn't it be detected during compile time? Syntax errors are supposed to be run time. Isn't it?
    Also, please elaborate what do you need when you say "command line options"?
  • Dorman Gareth said:
    If this is a syntax error, then shouldn't it be detected during compile time?

    It is.  

    C:\work\dir>type file.c
    void Call_This_Func(int len)
    {
       int array[len];
       array[0] = {0};
    }
    
    
    C:\work\dir>cl430 file.c
    "file.c", line 4: error: expected an expression
    "file.c", line 3: warning: variable "array" was set but never used
    1 error detected in the compilation of "file.c".
    
    >> Compilation failure

    To investigate this case, we need something we can run.  Please zip up your project as described in the article Project Sharing, then attach that zip file to your next post.

    Thanks and regards,

    -George

  • Dorman Gareth said:
    Also, please elaborate what do you need when you say "command line options"?

    Underneath Code Composer Studio, the compiler is implemented as a distinct program.  CCS calls this program as a command-line utility with arguments such as the file name to be compiled and the optimization level.  This is most easily seen in the build console window.  Build the project once and look at the build console window for a line beginning with "cl430."  If you share the project as George recommends, we will be able to figure out the compiler command-line options from the project.

  • Since it has been a while, I presume you have resolved your issue. I'd appreciate hearing how you resolved it.

    Thanks and regards,

    -George