Specifications

CAVR-4
212
Descriptions of extended keywords
AVR® IAR C/C++ Compiler
Reference Guide
__regvar
The __regvar extended keyword is used for declaring that a global or static variable
should be placed permanently in the specified register or registers. The registers
R4–R15
can be used for this purpose, provided that they have been locked with the
--lock_regs compiler option; see --lock_regs, page 186 for additional information.
Also see Preserved registers, page 101.
To declare a global register variable, use the following syntax:
__regvar __no_init type_name variable_name @ Rlocation
This will create a variable called variable_name of type type_name, located in
registers starting from Rlocation, for example:
__regvar __no_init int counter @ 14;
This will create the 16-bit integer variable counter, which will always be available in
R15:R14. At least two registers must be locked. And, as noted in -m, --memory_model,
page 186, if you lock any registers in your code, the library must be rebuilt with the same
set of locked registers.
The maximum object size is 4 bytes (32 bits).
Note: It is not possible to point to an object that has been declared
__regvar. An
object declared __regvar cannot have an initial value.
__root
The __root attribute can be used on a function or a variable to ensure that, when the
module containing the function or variable is linked, the function or variable is also
included, whether or not it is referenced by the rest of the program.
By default, only the part of the runtime library calling
main and any interrupt vectors
are root. All other functions and variables are included in the linked output only if they
are referenced by the rest of the program.
The __root keyword is placed in front of the type, for example to place myarray in
non-volatile memory:
__root int myarray[10];
The #pragma object_attribute directive can also be used. The following
declaration is equivalent to the previous one:
#pragma object_attribute=__root
int myarray[10];
Note: The __root keyword cannot be used in combination with the typedef
keyword.