Skip to main content

IAR Embedded Workbench for Arm 9.70.x

Supported GCC attributes

In this section:

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.

  • alias

  • aligned

    This attribute is supported on:

    • typedef declarations

    • enum types

    • struct and union types and members

    • variables, 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_inline

    In contrast to the GCC implementation, the attribute implies inline on the function, and no diagnostic message will be produced when always_inline is used on a non-inline function.

  • cmse_nonsecure_call

    See also __cmse_nonsecure_call.

  • cmse_nonsecure_entry

    See also __cmse_nonsecure_entry.

  • cold

    This 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.

  • const

  • constructor

    Functions with the attribute constructor will be called at the end of dynamic initialization—after static initialization, and before main is 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.

  • deprecated

  • format

  • hot

    This 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.

  • naked

  • noinit

    In 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_init keyword.

  • noinline

  • nonnull

    The attribute is recognized but has no effect.

  • noreturn

  • packed

    When used on an enum definition, the packed attribute has an effect only if the option ‑‑enum_is_int has 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 unaligned struct member accesses. To be informed of such accesses, use the IAR type attribute __packed.

  • pcs (for IAR type attributes used on functions)

  • pure

  • section

  • target (for IAR object attributes used on functions)

  • unused

  • used

  • visibility

    For reference information, see visibility.

  • volatile

  • warn_unused_result

  • weak

    Note that when the IAR attribute __weak is used on a declaration or on a tentative definition with a subsequent definition, the object is not made weak. Using the GCC-style attribute weak, the object will be made weak.

visibility

Syntax

__attribute__((visibility ("type"))

Parameters

type

One of these values:

  • default

  • hidden

  • internal

  • protected

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 visibility attribute cannot be used on types. Doing so causes a diagnostic message to be emitted.

  • Used on an extern declaration of an object, without a corresponding definition or tentative definition, the attribute has no effect.

  • The visibility type internal is treated as hidden by the linker.

Example
void
__attribute__((visibility ("hidden")))
myFunction() { }
See also

‑‑so_export and ‑‑visibility.