Type attributes
Type attributes define how a function is called, or how a data object is accessed. This means that if you use a type attribute, it must be specified both when a function or data object is defined and when it is declared.
You can either place the type attributes directly in your source code, or use the pragma directive
#pragma
type_attribute
.The following general type attributes are available:
You can specify as many type attributes as required for each level of pointer indirection.
To read more about the type qualifiers
const
andvolatile
, see the IAR C/C++ Development Guide for ARM®.Syntax for type attributes used on data objects
In general, type attributes for data objects follow the same syntax as the type qualifiers
const
andvolatile
.The following declaration assigns the
__little_endian
type attribute to the variablesi
andj
; in other words, the variablesi
andj
will be accessed with little endian byte order. The variablesk
andl
behave in the same way:Note that the attribute affects both identifiers.
The following declaration of
i
andj
is equivalent with the previous one:The advantage of using pragma directives for specifying keywords is that it offers you a method to make sure that the source code is portable. Note that the pragma directive has no effect if a memory attribute is already explicitly declared.
Syntax for type attributes on data pointers
The syntax for declaring pointers using type attributes follows the same syntax as the type qualifiers
const
andvolatile
:Syntax for type attributes on functions
The syntax for using type attributes on functions differs slightly from the syntax of type attributes on data objects. For functions, the attribute must be placed either in front of the return type, or in parentheses, for example:
or
The following declaration of
my_handler
is equivalent with the previous one:#pragma type_attribute=__irq __arm void my_handler(void);Object attributes
Object attributes affect the internal functionality of functions and data objects, but not how the function is called or how the data is accessed. This means that an object attribute does not need to be present in the declaration of an object.
The following object attributes are available:
You can specify as many object attributes as required for a specific function or data object.
For more information about
location
and@
, see the IAR C/C++ Development Guide for ARM®.Syntax for object attributes
The object attribute must be placed in front of the type. For example, to place
myarray
in memory that is not initialized at startup:The
#pragma
object_attribute
directive can also be used. The following declaration is equivalent to the previous one:
Type & Object attribute
最新推荐文章于 2024-08-20 06:00:00 发布