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.

sections for initialization

Hello,

The .cinit section contains variables and constants. As said in data sheet (compiler optimizer 187), when initialization, those variables are copied to .bss by c_int00.

Also it says .bss is reserved for all variables except far type. Then does that mean far type variable is also initialized by .cinit? Data sheet does not say anything about copying data from .cinit to .far.

Also, considering .cinit has constants inside, what are those constants different from constants inside const. section in the compiled module.

Both of them are initialized, why we need two sections to store constants.

Let's don't consider the load/run time initialization modes.

 

regards,

-Da

  • da cheng said:
    Then does that mean far type variable is also initialized by .cinit?

    With regard to initialization, far variables are handled the same as near (.bss) variables.

    da cheng said:
    Also, considering .cinit has constants inside, what are those constants different from constants inside const. section in the compiled module.

    Variables declared const and initialized are handled differently than others.  There is no need for the overhead of a record in the .cinit section.  Setting up space in memory and initializing that memory is done all at once.  Here is a simple example.  Code similar to this:

    const int array[] = { 1,2,3,4,5,6,7,8,9,10 };

    Turns into assembly that is similar to this:

    .sect ".const"
    _array:   .word 1,2,3,4,5,6,7,8,9,10

    The actual compiler output is different, but has the same net effect.  Note how this uses much less memory than using a .cinit record.

    Thanks and regards,

    -George

     

  • Hello George,

    1) From your reply, can I say there is no table or data for the initialization of constant in .cinit? .cinit is only used for non-const variables, right?

    2) If so, constants are directly accessed in the ROM? In my opinion, the .const section is stored in ROM.

     

    -DA

     

  • FYI:

    .const section variables can be stored pretty much anywhere you can normally put output sections.  They are not necessarily in ROM... the C standard just says that write accesses to const variables results in undefined behavior.  My .const sections are stored in DDR2 memory, which is not ROM.

  • Avoid worrying about unnecessary detail such as exactly which variables are affect by .cinit.  The important point is this:  The .const and .cinit sections do not change once loaded into system memory.  Thus, it is possible (not required) to place them in non-volatile memory such as Flash or ROM.  

    Thanks and regards,

    -George