Contiguous variables
Technical Note 75313
Architectures:
ARM
Component:
linker
Updated:
2018/12/13 14:34
Introduction
This technical note describes how to enforce placement of variables in a specified order.
Discussion
The following methods of placing variables are described:
- using section names
- using a reserved space
- using symbol names
- using an anonymous struct
Using section names
In your source code, use the @
operator to place variables in named sections.
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};
In your linker configuration file, use a fixed order block to define the order between the variables by selecting the section names assigned to each variable.
define block ARRAYS with fixed order
{
section 1st,
section 2nd,
section 3rd
};
Using a reserved space
This method can be used if your application requires some reserved space between variables.
In your linker configuration file, define a block with a fixed size, to represent the reserved RAM space, and in the fixed order block, place the reserved space block between variables.
define block RESERVED_SPACE with alignment = 8, size = 1024 { };
define block ARRAYS with fixed order
{
section 1st,
block RESERVED_SPACE,
section 3rd
};
Using symbol names
In your source code, declare variables which are not placed in named sections.
int ab[] = {1, 2, 3, 4, 5, 6, 7, 8};
int a[] = {1, 2, 3, 4, 5 };
int abc[] = {1, 2, 3, 4, 5, 6, 7};
In your linker configuration file, use a fixed order block to define the order between the variables by selecting the symbol names.
define block ARRAYS with fixed order
{
symbol ab,
symbol a,
symbol abc
};
Using an anonymous struct
Use IAR C language extensions to declare an "anonymous struct" to place variables in a specified order without using linker directives.
struct
{
int a;
char b;
int c;
};
For more information, see the sections Enabling language extensions and Anonymous structs and unions in C/C++ Development Guide available from the Help menu in the IDE.
Conclusion
To place variables in a specified order, you can use linker directives to define a fixed order block and select section names/symbol names, or use an anonymous struct.
This example contains a project for each of the described methods.
All product names are trademarks or registered trademarks of their respective owners.