Atmel CAVR-4 Manual De Usuario
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.
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.
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.
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.
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.