Contiguous variables

Technical Note 75313



9/7/2015 3:46 PM


This technical note is focused on the need to force fixed order of placement in RAM, that is, for situations when making a 'struct' isn't feasible.

Example projects are found in the Example project (ContiguousVariables).zip .

Issue 1

Using pragma location you can place variables in a section, but the .map file shows that the variables are placed in arbitrary order.

Solution 1

To enforce order between variables, place variables in separate sections and then declare a "fixed order block" to define the order between the variables, i.e. the order of the sections.

Note that this "fixed order block" will also be placed at an arbitrary location, but with linker directives the placement of the block can be controlled.

Example of C source showing variables placed in separate sections named "1st", "2nd" and "3rd":

int ab[]   @ "1st" = {1, 2, 3, 4, 5, 6, 7, 8};
int a[] @ "2nd" = {1, 2, 3, 4, 5 };
int abc[] @ "3rd" = {1, 2, 3, 4, 5, 6, 7};

Example of linker configuration directives defining the order between the sections where the variables are located:

define block ARRAYS with fixed order
section 1st,
section 2nd,
section 3rd

place in RAM_region { first block ARRAYS, readwrite, ... };

// The directive "first block" will place the block first in the RAM_region.

Issue 2

Instead of section "2nd", in the above example, some reserved RAM space is needed between the variables in section "1st" and "3rd".

Solution 2

Define a block which is placed between the variables and then use the linker directive "keep" to force the block to be included.

Modify the .icf file in the above example and use the following linker directives:

define block RESERVED_SPACE with alignment = 8, size = 1024 { };

define block ARRAYS with fixed order
section 1st,
section 3rd

keep { block RESERVED_SPACE };


All product names are trademarks or registered trademarks of their respective owners.

Related Tech Notes

© IAR Systems 1995-2018 - All rights reserved.

We use cookies on this website to provide you with a better experience. You need to accept cookies to continue using this site. Cookies