Loading...
Searching...
No Matches
modules.h File Reference

Common macros and compiler attributes/pragmas configuration. More...

Detailed Description

Common macros and compiler attributes/pragmas configuration.

Author
René Kijewski rene..nosp@m.kije.nosp@m.wski@.nosp@m.fu-b.nosp@m.erlin.nosp@m..de
Michel Rottleuthner miche.nosp@m.l.ro.nosp@m.ttleu.nosp@m.thne.nosp@m.r@haw.nosp@m.-ham.nosp@m.burg..nosp@m.de

Definition in file modules.h.

+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

#define IS_ACTIVE(macro)   __is_active(macro)
 Allows to verify a macro definition outside the preprocessor.
 
#define IS_USED(module)   IS_ACTIVE(module)
 Checks whether a module is being used or not.
 

Macro Definition Documentation

◆ IS_ACTIVE

#define IS_ACTIVE (   macro)    __is_active(macro)

Allows to verify a macro definition outside the preprocessor.

This macro is based on Linux's clever 'IS_BUILTIN' (https://github.com/torvalds/linux/blob/master/include/linux/kconfig.h). It takes a macro value that may be defined to 1 or not even defined (e.g. FEATURE_FOO) and then expands it to an expression that can be used in C code, either 1 or 0.

The advantage of using this is that the compiler sees all the code, so checks can be performed, sections that would not be executed are removed during optimization. For example:

if (IS_ACTIVE(FEATURE_FOO)) {
do_something();
}
#define IS_ACTIVE(macro)
Allows to verify a macro definition outside the preprocessor.
Definition modules.h:60
Parameters
[in]macroMacro to evaluate
Returns
1 if the macro is defined to 1
0 if the macro is not defined, of if it is defined to something else than 1.
Note
This should only be used when macros are defined as 1, it will not work if the macro value is, for example, (1) or 1U.
Although this may seem to work similarly to the preprocessor's 'defined', it is not entirely equal. If the given macro has been defined with no value, this will expand to 0. Also note that this is intended to be used with 'boolean' macros that act as switches, and usually will be defined as 1 or not defined.

Definition at line 60 of file modules.h.

◆ IS_USED

#define IS_USED (   module)    IS_ACTIVE(module)

Checks whether a module is being used or not.

Can be used in C conditionals.

Parameters
[in]moduleModule to check
Returns
1 if the module is being used
0 if the module is not being used

Definition at line 71 of file modules.h.