Cosmic UK Cosmic US Cosmic Germany Cosmic Italia Cosmic France

Cosmic Software Frequently Asked Questions

How do I force the compiler to allocate data objects in the order I declare them. It seems some are allocated in the reverse order and some are allocated in the order declared.

You should try not to rely on the allocation order of data objects as ANSI rules define allocation of data objects as an implementation defined behavior meaning compilers are free to allocate them in any order. This is useful for sorting data for word alignment or for allocation convenience. ANSI C structures and arrays are designed for the purposes of ordered allocation. In general, Cosmic compilers allocate initialized data (.data) in the order defined in the C code and reverse order for uninitialized data (BSS). You can use the +nobss option to force all data objects to be initialized and therefore allocated in the order defined. However, this will require more code space to store the initialized data and a longer startup as the data is copied back into RAM.