| |||
| Home > ARM Compiler Reference > GNU extensions to the ARM compiler > Function attributes | |||
This section describes the function attributes that are supported:
The compiler accepts multiple aliases for functions of the form:
newname __attribute__ ((alias “oldname”));
Where a function exists, the alias call is replaced by a call to the function, and the alias is emitted alongside the original name. Where a function does not exist, the alias call is replaced by a call to the real function. Where a function is static, the function name is replaced by the alias name (and the function declared external if required).
Supported in GNU mode only.
The always_inline function attribute indicates
that a function must be inlined.
static int b __attribute__ ((always_inline));
The compiler attempts to inline the function, regardless of the characteristics of the function. However, the compiler does not inline a function if doing so causes problems, for example, a recursive function is inlined only once.
Supported in GNU mode only.
The ARM mode equivalent (see Function storage class qualifiers) is __forceinline.
Many functions examine only the arguments passed to them,
and have no effects except for the return value. This is a much
stricter class than __attribute__((pure)) (see pure), because a function
is not permitted to read global memory. If a function is known to
operate only on its arguments then it can be subject to common subexpression
elimination and loop optimizations.
int Function_Attributes_const_0(int b) __attribute__ ((const));
int Function_Attributes_const_2(int b)
{
int aLocal=0;
aLocal += Function_Attributes_const_0(b);
aLocal += Function_Attributes_const_0(b);
return aLocal;
}
In this code Function_Attributes_const_0 might
be called once only, and the result is doubled to get the correct
return value.
Supported in GNU mode and ARM mode.
The deprecated function attribute indicates
that a function exists but the compiler must generate a warning
if the deprecated function is used.
int Function_Attributes_deprecated_0(int b) __attribute__ ((deprecated));
Supported in GNU mode and ARM mode.
The malloc function attribute indicates
that the function can be treated like malloc and the
associated optimizations can be performed.
void * Function_Attributes_malloc_0(int b) __attribute__ ((malloc));
Supported in GNU mode only.
The noinline function attribute suppresses
the inlining of a function at the call points of that function.
static int b __attribute__ ((noinline));
Supported in GNU mode only.
The noreturn function attribute informs
the compiler that the function does not return. The compiler can
then perform optimizations by removing the code that is never reached.
int Function_Attributes_NoReturn_0(void) __attribute__ ((noreturn));
Supported in GNU mode only.
The ARM mode equivalent (see Storage class modifiers) is __declspec(noreturn),
for example:
__declspec(noreturn) int Function_Attributes_NoReturn_0(void);
Many functions have no effects except to return a value, and that the return value depends only on the parameters and global variables. Functions of this kind can be subject to data flow analysis and might be eliminated, for example:
int Function_Attributes_pure_0(int b) __attribute__ ((pure));
int Function_Attributes_pure_0(int b)
{
static int aStatic;
aStatic++;
return b++;
}
int Function_Attributes_pure_2(int b)
{
int aLocal=0;
aLocal += Function_Attributes_pure_0(b);
return 0;
}
Here, the call to Function_Attributes_pure_0 might
be eliminated because its result is not used.
Supported in GNU mode only.
Using __attribute__((pure)) is equivalent
to using __pure (see Function qualifiers). __pure is supported
in GNU Mode as well as ARM mode.
The section function attribute enables
you to place code in different sections of the image.
void Function_Attributes_section_0 (void) __attribute__ ((section ("new_section")));
void Function_Attributes_section_0 (void)
{
static int aStatic =0;
aStatic++;
}
In this example, Function_Attributes_section_0 is
placed into the RO section new_section rather
than .text.
The section function attribute interacts
with #pragma arm section in that it overrides
that setting (see Pragmas controlling code generation for
more details.) For example:
#pragma arm section code="foo" int f2() { return 1; } // into the 'foo' area __attribute__ ((section ("bar"))) int f3() { return 1;} // into the 'bar' area int f4() { return 1; } // into the 'foo' area
#pragma arm section
Supported in GNU mode only.
The unused function attribute prevents
the compiler from generating warnings if the function is not referenced.
This does not change the behavior of the unused function removal
process.
static int Function_Attributes_unused_0(int b) __attribute__ ((unused));
Supported in GNU mode only.
Functions defined with __attribute__((weak)) export
their symbols weakly. For example:
extern int Function_Attributes_weak_0 (int b) __attribute__ ((weak));
Functions declared with __attribute__((weak)) and
then defined without __attribute__((weak)) behave
as weak functions. This is not the same behavior
as the __weak keyword (see Weak functions for details).
Supported in GNU mode and ARM mode.