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.

How to initialize un-initialized structure fields ?



Hi there,

Compiler: TI v4.9.1 (ARM9)
Initialization model: -c
Target OS: non-Linux RTOS
Problem: how to have following fooA.b and fooB.b reset to 0 by RTS loader without increasing the ROM image size drastically (<=256 bytes) ?

------------- code slice begin ---------------------------
typedef struct
{
 int a, b[1024];
}TFoo;

Foo fooA = { .a = 3 };
const Foo fooB = { .a = 5 };
------------- code slice end   ---------------------------

Thanks & regards,
Yulin.

  • I don't know anything about the loader in any RTOS.  I can tell you what the compiler will do.  Which ABI are you using?  ti_arm9_abi or EABI?

    Thanks and regards,

    -George

  • Hi George,

    Thanks for taking care of this.

    The RTOS and the app are linked in a single .out and the TI RTS loader is the only loader involved.
    There is no loader in the RTOS.

    I use ti_arm9_abi.
    For future design, please share for both ABI per this isse.

    Thanks & regards,
    Yulin.

     

  • Yulin said:
    the TI RTS loader is the only loader involved.

    I'm not sure what you mean.  The RTS that comes with the compiler does not have a loader.

    When built with ti_arm9_abi, fooA (which is not const) is allocated space in the .bss section.  It only gets a small initialization record which sets the member .a to 3.  The rest of fooA is left uninitialized. That doesn't take up much space.  fooB (which is const) is allocated space in the .const section.  All of fooB is initialized.  That takes up a fair amount of space.  You can avoid that by removing the const for fooB.  

    When built with eabi, fooA is allocated to .data, and fooB is allocated to .const.  They are both fully initialized, which takes up a fair amount of space.  Avoiding that initialization data space is bit more difficult.  You can't initialize fooA or fooB at all.  Then they are allocated to .bss.  

    Hope this helps ...

    -George

  • I mean the TI RTS is the only module linked to caters the init issue mentioned in this thread.

    Based on your reply, TI RTS does not support such auto reset of structure fields not explicitly specified and taking only O(1) ROM consumption.