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: MSP430 What is the proper syntax to call main() from boot.c?

Tool/software: TI C/C++ Compiler

I have noticed over the various versions of CCS that they supply different boot.c files for the MSP430. The only difference is that the call to main() will either pass data or not pass data, yet the main() function in our project is declared as void of parameters.

I'm a little worried that the compiler may inadvertently produce a bug because of this.

Which is the proper syntax to call main() from boot.c?

  • main();
  • main(void);
  • main(0);

  • I presume you intend to pass no arguments to main.

    For that case, look at how the boot routine in the compiler RTS library calls main.  The source code for the RTS library is part of the compiler installation.  The file is named boot.c and a typical directory location is ...

    C:\ti\ccs1011\ccs\tools\compiler\ti-cgt-msp430_20.2.1.LTS\lib\src\boot.c

    The syntax used in that file is ...

    main(0);

    Why is 0 passed as an argument?  In most cases, such as yours, it is harmless.  However, consider a case where some code is quickly ported from elsewhere, and there is code at the start of main which starts in a manner similar to ...

    int main(int argc, char *argv[])
    {
       int i;
       for (i = 0; i < argc; i++)
          process_argument(argv[i]);
       
       /* more code here */ 
    }

    By passing 0 as the first argument to main, this code is safely bypassed.  

    Thanks and regards,

    -George

  • Great answer. Thanks George.

  • Just one other question. I don't think it's good idea to pass data into main() that way. Instead, I would use the _system_pre_init() function. Would you use (int argc, char *argv[]) to pass data into main()?

  • Please describe the data you need main to receive as input.  Where does it come from?  

    Thanks and regards,

    -George