Specifications
CAVR-4
28
Function storage
AVR® IAR C/C++ Compiler
Reference Guide
Syntax
The extended keywords are specified before the return type, for example:
__interrupt void alpha(void);
The keywords that are type attributes must be specified both when they are defined and
in the declaration. Object attributes only have to be specified when they are defined
since they do not affect the way an object or function is used.
In addition to the rules presented here—to place the keyword directly in the code—the
directives #pragma type_attribute and #pragma object_attribute can be used
for specifying the keywords. Refer to the chapter Pragma directives for details about
how to use the extended keywords together with pragma directives.
Function storage
There are two memory attributes for controlling function storage:__nearfunc and
__farfunc
.
The following table summarizes the characteristics for each memory attribute:
When using the -v5 or the -v6 option, it is possible, for individual functions, to override
the __farfunc attribute and instead use the __nearfunc attribute. The default
memory attribute can be overridden by explicitly specifying a memory attribute in the
function declaration or by using the
#pragma type_attribute directive:
#pragma type_attribute=__nearfunc
void MyFunc(int i)
{
...
}
It is possible to call a __nearfunc function from a __farfunc function and vice versa.
Only the size of the function pointer is affected. Note that pointers with function
memory attributes have restrictions in implicit and explicit casts when casting between
pointers and also when casting between pointers and integer types; see Casting, page
142. For more information about function pointers, see Function pointers, page 141.
It is possible to place functions into named segments using either the
@ operator or the
#pragma location directive. For more information, see Controlling data and function
placement, page 47.
Memory attribute Address range Pointer size Used in processor option
__nearfunc 0-0x1FFFE (128 Kbytes) 16 bits -v0, -v1, -v2, -v3, -v4
__farfunc 0-0x7FFFFE (8 Mbytes) 24 bits -v5, -v6
Table 8: Memory attributes for functions