3.1 Function attributes

The __attribute__ keyword enables you to specify special attributes of variables, structure fields, functions, and types.

The keyword format is either of the following:
__attribute__((attribute1, attribute2, ...))
__attribute__((__attribute1__, __attribute2__, ...))
For example:
int my_function(int b) __attribute__((const));
static int my_variable __attribute__((__unused__));
The following table summarizes the available function attributes.

Table 3-1 Function attributes that the compiler supports, and their equivalents

Function attribute Non-attribute equivalent
__attribute__((alias)) -
__attribute__((always_inline)) -
__attribute__((const)) -
__attribute__((constructor[(priority)])) -
__attribute__((deprecated)) -
__attribute__((destructor[(priority)])) -
__attribute__((format_arg(string-index))) -
__attribute__((malloc)) -
__attribute__((noinline)) __declspec(noinline)
__attribute__((nomerge)) -
__attribute__((nonnull)) -
__attribute__((noreturn)) __declspec(noreturn))
__attribute__((nothrow)) __delspec(nothrow)
__attribute__((notailcall)) -
__attribute__((pcs("calling_convention"))) -
__attribute__((pure)) -
__attribute__((section("name"))) -
__attribute__((unused)) -
__attribute__((used)) -
__attribute__((visibility("visibility_type"))) -
__attribute__((weak)) -
__attribute__((weakref("target"))) -

Usage

You can set these function attributes in the declaration, the definition, or both. For example:
void AddGlobals(void) __attribute__((always_inline));
__attribute__((always_inline)) void AddGlobals(void) {...}
When function attributes conflict, the compiler uses the safer or stronger one. For example, __attribute__((used)) is safer than __attribute__((unused)), and __attribute__((noinline)) is safer than __attribute__((always_inline)).
Related reference
3.2 __attribute__((always_inline)) function attribute
3.5 __attribute__((const)) function attribute
3.6 __attribute__((constructor[(priority)])) function attribute
3.7 __attribute__((format_arg(string-index))) function attribute
3.8 __attribute__((malloc)) function attribute
3.10 __attribute__((nonnull)) function attribute
3.9 __attribute__((noinline)) function attribute
3.13 __attribute__((pcs("calling_convention"))) function attribute
3.14 __attribute__((pure)) function attribute
3.11 __attribute__((noreturn)) function attribute
3.12 __attribute__((nothrow)) function attribute
3.15 __attribute__((section("name"))) function attribute
3.17 __attribute__((unused)) function attribute
3.16 __attribute__((used)) function attribute
3.18 __attribute__((visibility("visibility_type"))) function attribute
3.19 __attribute__((weak)) function attribute
3.20 __attribute__((weakref("target"))) function attribute
2.2 __alignof__
2.3 __asm
2.4 __declspec attributes
Non-ConfidentialPDF file icon PDF versionARM DUI0774E
Copyright © 2014-2016 ARM. All rights reserved.