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
#pragmatype_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
constandvolatile, 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
constandvolatile.The following declaration assigns the
__little_endiantype attribute to the variablesiandj; in other words, the variablesiandjwill be accessed with little endian byte order. The variableskandlbehave in the same way:Note that the attribute affects both identifiers.
The following declaration of
iandjis 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
constandvolatile: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_handleris 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
locationand@, 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
myarrayin memory that is not initialized at startup:The
#pragmaobject_attributedirective can also be used. The following declaration is equivalent to the previous one:
Type & Object attribute
最新推荐文章于 2025-07-19 21:29:25 发布
本文详细介绍了在ARM体系中使用的类型属性与对象属性的概念及其语法。类型属性定义了函数调用的方式或数据对象的访问方式,而对象属性则影响函数和数据对象的内部功能。文章还提供了使用这些属性的具体示例。
1138

被折叠的 条评论
为什么被折叠?



