Commit b4cd9c46 authored by Pieter De Gendt's avatar Pieter De Gendt Committed by Fabio Baltieri
Browse files

sys: util_macro: Add IF_DISABLED



Add the opposite for IF_ENABLED macro.

Signed-off-by: default avatarPieter De Gendt <pieter.degendt@basalte.be>
parent be6cf5c2
Loading
Loading
Loading
Loading
+24 −0
Original line number Diff line number Diff line
@@ -223,6 +223,30 @@ extern "C" {
#define IF_ENABLED(_flag, _code) \
	COND_CODE_1(_flag, _code, ())

/**
 * @brief Insert code if @p _flag is not defined as 1.
 *
 * This expands to nothing if @p _flag is defined and equal to 1;
 * it expands to @p _code otherwise.
 *
 * Example:
 *
 *     IF_DISABLED(CONFIG_FLAG, (uint32_t foo;))
 *
 * If @p CONFIG_FLAG isn't defined or different than 1, this expands to:
 *
 *     uint32_t foo;
 *
 * and to nothing otherwise.
 *
 * IF_DISABLED does the opposite of IF_ENABLED.
 *
 * @param _flag evaluated flag
 * @param _code result if @p _flag does not expand to 1; must be in parentheses
 */
#define IF_DISABLED(_flag, _code) \
	COND_CODE_1(_flag, (), _code)

/**
 * @brief Check if a macro has a replacement expression
 *