![]() |
CAPS Universe documentation
1.0.4
All you need to know to be successful
|
Give hints to the compiler and the reader of the code. More...
Macros | |
| #define | __non_null |
| #define | __nonnull(params) |
| #define | __format(x, y) |
| #define | __format_arg(x) |
| #define | __packed |
| #define | __maybe_unused |
| #define | __deprecated |
| #define | __no_return |
| #define | __pure |
| #define | __const |
| #define | __cleanup(x) |
| #define | __returns_nonnull |
| #define | __warn_unused_res |
| #define | __fallthrough |
| #define | __cold |
| #define | __hot |
| #define | __nonstring |
These attributes are used to give the compiler and the user hints about the structures/functions/parameters for better static code analysis and understanding.
To avoid code duplication we define them here for all. Since we use features.h, all attributes are removed if the compiler cannot deal with it.
On the other hand we expect a GCC newer than the old 3.x days and all of these attributes should be understood by recent compilers. So, we define them here at most unconditionally.
| #define __non_null |
GCC function attribute: used to mark all arguments to be non-null
void function(void *foo, void *bar) __non_null;
| #define __nonnull | ( | params | ) |
GCC function attribute: used to mark all or specific arguments to be non-null
void function1(void *foo, void *bar) __nonnull(); // both arguments must be non-null void function2(void *foo, void *bar) __nonnull((2)); // the second argument must be non-null
| #define __format | ( | x, | |
| y | |||
| ) |
GCC function attribute: used to give the compiler a glue about the arguments and how to check them
| x | Parameter number of the format string (count starts with '1') |
| y | Parameter number of the first value string matching the format string (count starts with '1') |
| #define __format_arg | ( | x | ) |
GCC function attribute: used to give the compiler a glue about the arguments and how to check them
| x | FIXME |
| #define __packed |
GCC structure attribute: used to mark a structure to be non-aligned
| #define __maybe_unused |
GCC function/parameter attribute: used to mark a function or a parameter as maybe unused
| #define __deprecated |
GCC function attribute: used to mark a function as deprecated
| #define __no_return |
GCC function attribute: mark a function which does not return
| #define __pure |
GCC function attribute: mark a function to be pure (refer __const), e.g. it returns a value based only on its parameters and global variables.
| #define __const |
GCC function attribute: used to mark a function as const (refer __pure), e.g. it returns a value based only on its parameters.
| #define __cleanup | ( | x | ) |
GCC function attribute: define a cleanup function for an element
| x | FIXME |
| #define __returns_nonnull |
GCC function attribute: mark a function to never return a non-NULL value
| #define __warn_unused_res |
GCC function attribute: warn if a caller does not use the returned value
| #define __fallthrough |
GCC function attribute: do not warn if a switch/case fallthrough is intended
| #define __cold |
GCC function attribute: mark function for better branch prediction (here: the seldom chosen branch)
| #define __hot |
GCC function attribute: mark function for better branch prediction (here: the often chosen branch)
| #define __nonstring |
GCC variable attribute: mark an array as a non-string, e.g. no termination zero character available
unsigned char pattern[100] __nonstring;