While looking at the Linux kernel, I noticed the line:
static void *malloc(size_t size) __maybe_unused;
in Linux v3.2 /arch/frv/kernel/gdb_stub.c . I've never seen __maybe_unused
used before. Is it specific to the Linux kernel? Or is it defined in the C spec? And what exactly does it do?
In include/linux/compiler-gcc.h
there is the definition of the __maybe_unused
macro:
#define __maybe_unused __attribute__((unused))
and in gcc
manual you have the documentation of the unused
attribute for functions:
unused "This attribute, attached to a function, means that the function is meant to be possibly unused. GCC will not produce a warning for this function."
http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html
and for variables:
unused "This attribute, attached to a variable, means that the variable is meant to be possibly unused. GCC will not produce a warning for this variable."
http://gcc.gnu.org/onlinedocs/gcc/Variable-Attributes.html
From the commit that introduced the attribute:
__maybe_unused is defined to be __attribute__((unused)) for both function and variable use if it could possibly be unreferenced due to the evaluation of preprocessor macros. Function prototypes shall be marked with __maybe_unused if the actual definition of the function is dependant on preprocessor macros.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With