3.19 __attribute__((unused)) function attribute

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.

Note:

By default, the compiler does not warn about unused functions. Use -Wunused-function to enable this warning specifically, or use an encompassing -W value such as -Wall.

The __attribute__((unused)) attribute can be useful if you usually want to warn about unused functions, but want to suppress warnings for a specific set of functions.

Example

static int unused_no_warning(int b) __attribute__((unused));
static int unused_no_warning(int b)
{
  return b++;
}

static int unused_with_warning(int b);
static int unused_with_warning(int b)
{
  return b++;
}

Compiling this example with -Wall results in the following warning:

armclang --target=aarch64-arm-none-eabi -c test.c -Wall
test.c:10:12: warning: unused function 'unused_with_warning' [-Wunused-function]
static int unused_with_warning(int b)
           ^
1 warning generated.
Non-ConfidentialPDF file icon PDF version100067_0609_00_en
Copyright © 2014–2017 Arm Limited (or its affiliates). All rights reserved.