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/TMS570LS3137-EP: Impact of main and cinit

Part Number: TMS570LS3137-EP


Tool/software: TI C/C++ Compiler

Hi,


1.I will not require the main function for one of my projects. if I compile without main, a warning is issued. apart from that, will there be any impact if there is no main in a project?

2. How exactly does the .cinit copy the initialized variables to RAM? (I don't have any code which does the job)

3.If I don't want any variable auto initialized, can I remove .cinit section from the linker file of that project?

  • Do you have any C or C++ code in the system?  If so, then I don't see how you cannot have a main function.  It is a deep presumption of the compiler that the entry point symbol is main.  

    Thanks and regards,

    -George

  • We would like to have main named in a different way, based on the functionality, rather than main. Reset vector jumps to this main function after reset. Because we did not name it as MAIN, compiler is issuing a warning. I would like to understand the behavior for following points:

    1. What are the implications of not having main (or rather not naming it as "MAIN")?

    Apart from this, I have following additional questions:
    2. How exactly does the .cinit copy the initialized variables to RAM? I did not completely understand this concept.

    3. The documentation says that it copies initialized section to RAM at power-up initialization. I don't have any code in my program that copies initialized section to RAM. My program does not initialize the variable at the time of declaration. We initialize them during power-up initialization. In this case, can I remove .cinit section from the linker file of that project?
  • Sharif Shaik said:
    1. What are the implications of not having main (or rather not naming it as "MAIN")?

    I don't know.  Really.  As far as I am aware, the only systems to not have a main function are completely implemented in hand-coded assembly.

    Sharif Shaik said:
    2. How exactly does the .cinit copy the initialized variables to RAM? I did not completely understand this concept.

    Please read the section titled System Initialization in the ARM compiler manual.  All of this initialization code is part of the compiler installation.  If you have CCS installed, then you can find it in a directory similar to ...

    C:\ti\ccsv6\tools\compiler\ti-cgt-arm_16.9.0.LTS\lib\src

    Start with the file boot.asm.  Then look at autoinit.c.

    All of this code is linked in automatically when you use the linker option --rom_model or --ram_model, and you have a function named main.  

    Sharif Shaik said:
    In this case, can I remove .cinit section from the linker file of that project?

    If you have C or C++ variables that must be initialized prior to the start of main, then the .cinit section is the only mechanism for initializing those variables that is provided by the compiler tools.

    Thanks and regards,

    -George