Atmel CAVR-4 ユーザーズマニュアル

ページ / 323
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:
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 
_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.
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.
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 
-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 
_ _flash
 pointer or a 
_ _generic
 
pointer, though neither of these are default pointers. Note that if you attempt to take the