Skip to main content

IAR Embedded Workbench for RISC-V 3.40

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.

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

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

  • 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 smallest possible underlying type is selected for the enum.

    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

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