Language extensions - iarsystems/ewptool GitHub Wiki
All IAR C/C++ compilers provide language extensions to allow programmers to be more productive, and to allow fine control over the code generation process. Language extensions can be classified in the following way:
- Generic extensions, not targeted to any architecture, but providing some feature seen to be missing in the language (e.g. inline functions in C, macros that can return values).
- Extensions designed to allow the programmer to control the placement of code and/or data (e.g. definition of the owning section).
- Extensions to provide special 'attributes' to functions or data to change the way they are treated by the compiler (e.g. interrupt handler functions, packed structures).
- Extensions to provide access to low level programming (in line assembler and intrinsic functions).
The extensions can be implemented as one or more of the following:
- Keywords: Very commonly used features (such as inline functions, or inline assembler) warrant a keyword to enable clear code to be written. The number of extended keywords is usually restricted to limit 'namespace pollution'.
- Attributes set via a single
__attribute__
keyword: This mechanism allows any number of attributes to be applied to the definition of a data object or function using a single extended keyword. This is usually the approach used with the GNU C Compiler. #pragma
directives: These look like pre-processor directives, and have implementation specific behavior. They have the advantage of not requiring any new keywords to support extended features, but suffer from the fact that they cannot be used in macros (like other directives), and usually toggle a feature on/off for the rest of the file, or until another #pragma directive is used to change the behavior.
Supported GCC attributes
In extended language mode, which can be activated with #pragma language=extended
, the IAR C/C++ Compiler automatically supports a selection of GCC-style attributes using the __attribute__((attribute-list))
syntax, significantly reducing migration efforts.
The following attributes are supported in part or in whole:
GCC-style attribute | Comments |
---|---|
alias |
|
aligned |
|
always_inline |
|
cmse_nonsecure_call |
(*Arm-specific) |
cmse_nonsecure_entry |
(*Arm-specific) |
const |
|
constructor |
|
deprecated |
|
format |
|
naked |
(*Arm only) |
noinline |
|
noreturn |
|
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] The table above applies to
Product Version IAR Embedded Workbench for Arm 9.40.1 IAR Embedded Workbench for RISC-V 3.20.1
The IAR C/C++ Compiler provides a large number of language extensions, allowing generation of powerful and highly targeted code. For more information refer to the "IAR C/C++ Development Guide" shipped with your product or, online, via your product's official page.