Syntax for Attribute Specifications
Remarks
Declaring a function's prototype with this declaration specification tells the compiler not to inline the function, even if the function is later defined with the inline
,
__inline__
, or
__inline
keywords.
23.2 Syntax for Attribute Specifications
The syntax for an attribute specification is
__attribute__((
list-of-attributes )) where list-of-attributes is a comma-separated list of zero or more attributes to associate with the object. Place an attribute specification at the end of the delcaration and definition
of a function, function parameter, or variable. Listing 23-1 on page 402 shows an
example.
Listing 23-1. Example of an attribute specification
int f(int x __attribute__((unused))) __attribute__((never_inline)); int f(int x __attribute__((unused))) __attribute__((never_inline))
{
return 20;
}
23.2.1 __attribute__((noreturn))
Specifies that a function will never return if it is called. This allows the compiler to make certain modifications to the control flow graph to improve the code generation. An example of an improvement would be to not conserve the LR or non-volatiles on the stack.
23.2.2 __attribute__((deprecated))
Specifies that the compiler must issue a warning when a program refers to an object.
Syntax
CodeWarrior Development Studio for Advanced Packet Processing Build Tools Reference Manual, Rev.
10.2, 01/2016
402 Freescale Semiconductor, Inc.
Chapter 23 Declaration Specifications
variable-declaration __attribute__((deprecated));
variable-definition __attribute__((deprecated));
function-declaration __attribute__((deprecated));
function-definition __attribute__((deprecated));
Remarks
This attribute instructs the compiler to issue a warning when a program refers to a function or variable. Use this attribute to discourage programmers from using functions and variables that are obsolete or will soon be obsolete.
Listing 23-2. Example of deprecated attribute
int velocipede(int speed) __attribute__((deprecated)); int bicycle(int speed); int f(int speed)
{
return velocipede(speed); /* Warning. */
} int g(int speed)
{
return bicycle(speed * 2); /* OK */
}
23.2.3 __attribute__((force_export))
Prevents a function or static variable from being dead-stripped.
Syntax
function-declaration __attribute__((force_export));
function-definition __attribute__((force_export));
variable-declaration __attribute__((force_export));
variable-definition __attribute__((force_export));
CodeWarrior Development Studio for Advanced Packet Processing Build Tools Reference Manual, Rev.
10.2, 01/2016
Freescale Semiconductor, Inc.
403
Syntax for Attribute Specifications
Remarks
This attribute specifies that the linker must not dead-strip a function or static variable even if the linker determines that the rest of the program does not refer to the object.
23.2.4 __attribute__((malloc))
Specifies that the pointers returned by a function will not point to objects that are already referred to by other variables.
Syntax
function-declaration __attribute__((malloc));
function-definition __attribute__((malloc));
Remarks
This attribute specification gives the compiler extra knowledge about pointer aliasing so that it can apply stronger optimizations to the object code it generates.
23.2.5 __attribute__((noalias))
Prevents access of data object through an indirect pointer access.
Syntax
function-parameter __attribute__((noalias));
variable-declaration __attribute__((noalias));
variable-definition __attribute__((noalias));
Remarks
CodeWarrior Development Studio for Advanced Packet Processing Build Tools Reference Manual, Rev.
10.2, 01/2016
404 Freescale Semiconductor, Inc.
Chapter 23 Declaration Specifications
This attribute specifies to the compiler that a data object is only accessed directly, helping the optimizer to generate a better code. The sample code in
Listing 23-3 on page 405 will
not return a correct result if ip
is pointed to a
.
Listing 23-3. Example of the noalias attribute
extern int a __attribute__((noalias)); int f(int *ip)
{
a = 1;
*ip = 0;
return a; // optimized to return 1;
}
23.2.6 __attribute__((returns_twice))
Specifies that a function may return more than one time because of multithreaded or nonlinear execution.
Syntax
function-declaration __attribute__((returns_twice));
function-definition __attribute__((returns_twice));
Remarks
This attribute specifies to the compiler that the program's flow of execution might enter and leave a function without explicit function calls and returns. For example, the standard library's setjmp()
function allows a program to change its execution flow arbitrarily.
With this information, the compiler limits optimizations that require explicit program flow.
23.2.7 __attribute__((unused))
Specifies that the programmer is aware that a variable or function parameter is not referred to.
Syntax
function-parameter __attribute__((unused));
CodeWarrior Development Studio for Advanced Packet Processing Build Tools Reference Manual, Rev.
10.2, 01/2016
Freescale Semiconductor, Inc.
405
Syntax for Attribute Specifications
variable-declaration __attribute__((unused));
variable-definition __attribute__((unused));
Remarks
This attribute specifies that the compiler should not issue a warning for an object if the object is not referred to. This attribute specification has no effect if the compiler's unused warning setting is off.
Listing 23-4. Example of the unused attribute
void f(int a __attribute__((unused))) /* No warning for a. */
{
int b __attribute__((unused)); /* No warning for b. */
int c; /* Possible warning for c. */
return 20;
}
23.2.8 __attribute__((used))
Prevents a function or static variable from being dead-stripped.
Syntax
function-declaration __attribute__((used));
function-definition __attribute__((used));
variable-declaration __attribute__((used));
variable-definition __attribute__((used));
Remarks
This attribute specifies that the linker must not dead-strip a function or static variable even if the linker determines that the rest of the program does not refer to the object.
CodeWarrior Development Studio for Advanced Packet Processing Build Tools Reference Manual, Rev.
10.2, 01/2016
406 Freescale Semiconductor, Inc.
Chapter 23 Declaration Specifications
23.2.9 __attribute__((never_inline))
Specifies that a function must not be inlined.
Syntax
__attribute__((never_inline)) function_prototype ;
Remarks
Declaring a function's prototype with this attribute tells the compiler not to inline the function, even if the function is later defined with the inline
,
__inline__
, or
__inline keywords.
CodeWarrior Development Studio for Advanced Packet Processing Build Tools Reference Manual, Rev.
10.2, 01/2016
Freescale Semiconductor, Inc.
407
Syntax for Attribute Specifications
CodeWarrior Development Studio for Advanced Packet Processing Build Tools Reference Manual, Rev.
10.2, 01/2016
408 Freescale Semiconductor, Inc.