Atmel CAVR-4 ユーザーズマニュアル
![Atmel](https://files.manualsbrain.com/attachments/0369829915bda09f9c2e00fb805a7753579683b5/common/fit/150/50/8d2bf08978ec3e5bc63f4343ac5e91ce8d0e40045619fa520d910d64af8f/brand_logo.png)
CAVR-4
40
Data segments
AVR® IAR C/C++ Compiler
Reference Guide
3 Finally, global C++ objects are constructed, if any.
Initialization of local aggregates at function invocation
Initialized aggregate auto variables—struct, union, and array variables local to a
function—have the initial values in blocks of memory As an auto variable is allocated
either in registers or on the stack, the initialization has to take place every time the
function is called. Assume the following example:
function—have the initial values in blocks of memory As an auto variable is allocated
either in registers or on the stack, the initialization has to take place every time the
function is called. Assume the following example:
void f()
{
struct block b = { 3, 4, 2, 3, 6634, 234 };
...
}
The initializers are copied to the
b
variable allocated on the stack each time the function
is entered.
The initializers can either come from the code memory space (flash) or from the data
memory space (optional external ROM). By default, the initializers are located in
segments with the suffix
memory space (optional external ROM). By default, the initializers are located in
segments with the suffix
_C
and these segments are copied from external ROM to the
stack.
If you use either the
-y
option or the
--initializers_in_flash
option, the
aggregate initializers are located in segments with the suffix
_F
, which are copied from
flash memory to the stack. The advantage of storing these initializers in flash is that
valuable data space is not wasted. The disadvantage is that copying from flash is slower.
valuable data space is not wasted. The disadvantage is that copying from flash is slower.
Initialization of constant objects
There are different ways of initializing constant objects.
By default, constant objects are placed in segments with the suffix
_C
, which are located
in the optional external ROM that resides in the data memory space. The reason for this
is that it must be possible for a default pointer—a pointer without explicit memory
attributes—to point to the object, and a default pointer can only point to the data
memory space.
is that it must be possible for a default pointer—a pointer without explicit memory
attributes—to point to the object, and a default pointer can only point to the data
memory space.
However, if you do not have any external ROM in the data memory space, and for single
ship applications you most likely do not have it, the constant objects have to be placed
in RAM and initialized as any other non-constant variables. To achieve this, use the
ship applications you most likely do not have it, the constant objects have to be placed
in RAM and initialized as any other non-constant variables. To achieve this, use the
-y
option, which means the objects are placed in segments with the suffix
_ID
.
if you want to place an object in flash, you can use any of the memory attributes
_ _tinyflash
,
_ _flash
,
_ _farflash
, or
_ _hugeflash
. The object becomes a flash
object, which means you cannot take the address of it and store it in a default pointer.
However, it is possible to store the address in either a
However, it is possible to store the address in either a
_ _flash
pointer or a
_ _generic
pointer, though neither of these are default pointers. Note that if you attempt to take the