#205 __no_init attribute for static variables

open
nobody
None
5
2007-05-08
2007-05-08
Anonymous
No

There are cases when static variable need to be not initialized implicitly by C startup code. Example - battery backed RAM, or code acting differently after POR reset and other resets (preserves some info in RAM during non-POR resets).
Just in case: patjank wp pl (add 'at' and dot).

Discussion

  • Maarten Brock

    Maarten Brock - 2007-05-08

    Logged In: YES
    user_id=888171
    Originator: NO

    Not claiming that this is the best solution, but something like this is already possible:

    If you create your own _sdcc_external_startup function and let it return a non-zero value all initialisation will be skipped.

    Or if you place your variable at an absolute address and do not give it an initializer, it will not be initalized to zero. But you must make sure the absolute address does not overlap the normally used xdata. E.g. place it at 0x0300 and limit normal xdata with --xram-size 0x0300.

    Maarten

     
  • Patryk

    Patryk - 2007-05-08

    Logged In: YES
    user_id=1788180
    Originator: NO

    I know that solutions.

    "If you create your own _sdcc_external_startup function and let it return a
    non-zero value all initialisation will be skipped."
    All initialisation will be skipped - great cost for only a few no_init variables or one area.

    "But you must make sure the absolute address does not overlap the normally used xdata."
    9 January you wrote on SiLabs forum that compiler reserves space for data/idata variables placed with __at, but not yet pdata/xdata. So can I forget about overlap when using data/idata? I.e. linker will give warning when overlap happens? Still need to choose address anyway, not convenient when few variables used, especially when some only for debug.

     
  • Maarten Brock

    Maarten Brock - 2007-05-08

    Logged In: YES
    user_id=888171
    Originator: NO

    I did not say my solutions were great, just a workaround. Yours is a valid feature request.

    I think I wrote the compiler reserves space if you DO give them an initializer. It does not so when they have no initializer. Data / idata / xdata should work, pdata might not.

    With initializer overlap should generate a warning. Overlap can only come from other absolute areas, normal stuff will be located around them. Only the stack might grow into your variable I think.

    Without initializer (what you need for non-initialized variables) you are responsible for overlap issues. Limiting data/xdata space is the easiest solution to still get warnings, use --xram-loc, --xram-size, --iram-size, --data-loc.

    HTH,
    Maarten

     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks