Supported GCC attributes
In extended language mode—when either --language=extended or --language=gnu has been specified—the IAR C/C++ Compiler also supports a limited selection of GCC-style attributes. Use the __attribute__ ((attribute-list)) syntax for these attributes.
The following attributes are supported in part or in whole. For more information, see the GCC documentation.
aliasalignedThis attribute is supported on:
typedefdeclarationsenumtypesstructanduniontypes and membersvariables, except register variables.
In contrast to the GCC implementation, the attribute is neither supported on functions nor on (pointer) function parameters. Additional limitations might also apply, such as auto variables not being allowed to have a stricter alignment than the stack.
always_inlineIn contrast to the GCC implementation, the attribute implies
inlineon the function, and no diagnostic message will be produced whenalways_inlineis used on a non-inline function.cmse_nonsecure_callSee also __cmse_nonsecure_call.
cmse_nonsecure_entrySee also __cmse_nonsecure_entry.
coldThis attribute sets the optimization goal for the function to optimizing for Size. If the optimization goal has also been set using
#pragma optimize, the GCC-style attribute overrides it. If there is a conflict, a warning will be issued.In contrast to the GCC implementation, the attribute can only be used as a function attribute, not in a label.
constconstructorFunctions with the attribute
constructorwill be called at the end of dynamic initialization—after static initialization, and beforemainis called. If the attribute is used on multiple functions, they will be called in the order of definition.The attribute is recognized, but has no effect, when used on objects compiled with the option
‑‑shared.deprecatedformathotThis attribute sets the optimization goal for the function to optimizing for Speed. If the optimization goal has also been set using
#pragma optimize, the GCC-style attribute overrides it. If there is a conflict, a warning will be issued.In contrast to the GCC implementation, the attribute can only be used as a function attribute, not in a label.
nakednoinitIn contrast to the GCC implementation, the attribute only applies to variables, and any such variable is treated as if it were declared with the IAR
__no_initkeyword.noinlinenonnullThe attribute is recognized but has no effect.
noreturnpackedWhen used on an enum definition, the
packedattribute has an effect only if the option‑‑enum_is_inthas been specified. In that case the smallest possible underlying type is selected for the enum. (This is otherwise the default behavior for the compiler).Note that when using the GCC-style attribute
packed, no diagnostics messages are produced for potential unalignedstructmember accesses. To be informed of such accesses, use the IAR type attribute__packed.pcs(for IAR type attributes used on functions)puresectiontarget(for IAR object attributes used on functions)unusedusedvisibilityFor reference information, see visibility.
volatilewarn_unused_resultweakNote that when the IAR attribute
__weakis used on a declaration or on a tentative definition with a subsequent definition, the object is not made weak. Using the GCC-style attributeweak, the object will be made weak.
visibility
Syntax
__attribute__((visibility ("type"))
Parameters
| One of these values:
|
Description
This attribute is supported in C mode. Code that uses it must be compiled with the option ‑‑shared. Otherwise, the attribute is recognized but has no effect. It can be used with functions and variables.
These limitations apply:
The
visibilityattribute cannot be used on types. Doing so causes a diagnostic message to be emitted.Used on an
externdeclaration of an object, without a corresponding definition or tentative definition, the attribute has no effect.The visibility type
internalis treated ashiddenby the linker.
Example
void
__attribute__((visibility ("hidden")))
myFunction() { }See also
‑‑so_export and ‑‑visibility.