Atmel CAVR-4 ユーザーズマニュアル
![Atmel](https://files.manualsbrain.com/attachments/0369829915bda09f9c2e00fb805a7753579683b5/common/fit/150/50/8d2bf08978ec3e5bc63f4343ac5e91ce8d0e40045619fa520d910d64af8f/brand_logo.png)
CAVR-4
128
Selecting data types and placing data in memory
AVR® IAR C/C++ Compiler
Reference Guide
MEMORY MODEL AND MEMORY ATTRIBUTES FOR DATA
For many applications it is sufficient to use the memory model feature to specify the
default memory for the data objects. However, for individual objects it might be
necessary to specify other memory attributes in certain cases, for example:
default memory for the data objects. However, for individual objects it might be
necessary to specify other memory attributes in certain cases, for example:
●
An application where some global variables are accessed from a large number of
locations. In this case they can be declared to be placed in memory with a smaller
pointer type
locations. In this case they can be declared to be placed in memory with a smaller
pointer type
●
An application where all data, with the exception of one large chunk of data, fits
into the region of one of the smaller memory types
into the region of one of the smaller memory types
●
Data that must be placed at a specific memory location.
The AVR IAR C/C++ Compiler provides memory attributes for placing data objects in
the different memory spaces, and for the DATA and CODE space (flash) there are
different memory attributes for placing data objects in different memory types, see
Extended keywords for data, page 16.
the different memory spaces, and for the DATA and CODE space (flash) there are
different memory attributes for placing data objects in different memory types, see
Extended keywords for data, page 16.
Efficient usage of memory type attributes can significantly reduce the application size.
For details about the memory types, see Memory types and memory attributes, page 18.
USING THE BEST POINTER TYPE
The generic pointers, pointers declared
_ _generic
, can point to all memory spaces,
which makes them simple and also tempting to use. However, they carry a cost in that
special code is needed before each pointer access to check which memory a pointer
points to and performing appropriate actions. Use the smallest pointer type you can, and
avoid any generic pointers unless necessary. For details about available pointer types,
see Pointer types, page 141.
special code is needed before each pointer access to check which memory a pointer
points to and performing appropriate actions. Use the smallest pointer type you can, and
avoid any generic pointers unless necessary. For details about available pointer types,
see Pointer types, page 141.
ANONYMOUS STRUCTS AND UNIONS
When declaring a structure or union without a name, it becomes anonymous. The effect
is that its members will only be seen in the surrounding scope.
is that its members will only be seen in the surrounding scope.
Anonymous structures are part of the C++ language; however, they are not part of the C
standard. In the AVR IAR C/C++ Compiler they can be used in C if language extensions
are enabled.
standard. In the AVR IAR C/C++ Compiler they can be used in C if language extensions
are enabled.
In IAR Embedded Workbench, language extensions are enabled by default.
Use the
-e
compiler option to enable language extensions. See -e, page 179, for
additional information.