CAPS Universe documentation  1.0.4
All you need to know to be successful
Macros

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
 

Detailed Description

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.

Macro Definition Documentation

◆ __non_null

#define __non_null

GCC function attribute: used to mark all arguments to be non-null

 void function(void *foo, void *bar) __non_null;
Note
This is a convenience macro only. The regular form is __nonnull() for this use case.

◆ __nonnull

#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
Note
This macro is from compiler's features.h

◆ __format

#define __format (   x,
 
)

GCC function attribute: used to give the compiler a glue about the arguments and how to check them

Parameters
xParameter number of the format string (count starts with '1')
yParameter number of the first value string matching the format string (count starts with '1')

◆ __format_arg

#define __format_arg (   x)

GCC function attribute: used to give the compiler a glue about the arguments and how to check them

Parameters
xFIXME

◆ __packed

#define __packed

GCC structure attribute: used to mark a structure to be non-aligned

◆ __maybe_unused

#define __maybe_unused

GCC function/parameter attribute: used to mark a function or a parameter as maybe unused

◆ __deprecated

#define __deprecated

GCC function attribute: used to mark a function as deprecated

◆ __no_return

#define __no_return

GCC function attribute: mark a function which does not return

◆ __pure

#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.

◆ __const

#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.

◆ __cleanup

#define __cleanup (   x)

GCC function attribute: define a cleanup function for an element

Parameters
xFIXME

◆ __returns_nonnull

#define __returns_nonnull

GCC function attribute: mark a function to never return a non-NULL value

◆ __warn_unused_res

#define __warn_unused_res

GCC function attribute: warn if a caller does not use the returned value

◆ __fallthrough

#define __fallthrough

GCC function attribute: do not warn if a switch/case fallthrough is intended

◆ __cold

#define __cold

GCC function attribute: mark function for better branch prediction (here: the seldom chosen branch)

◆ __hot

#define __hot

GCC function attribute: mark function for better branch prediction (here: the often chosen branch)

◆ __nonstring

#define __nonstring

GCC variable attribute: mark an array as a non-string, e.g. no termination zero character available

 unsigned char pattern[100] __nonstring;