Skip to content

Commit b4cd9c4

Browse files
pdgendtfabiobaltieri
authored andcommitted
sys: util_macro: Add IF_DISABLED
Add the opposite for IF_ENABLED macro. Signed-off-by: Pieter De Gendt <[email protected]>
1 parent be6cf5c commit b4cd9c4

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

include/zephyr/sys/util_macro.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,30 @@ extern "C" {
223223
#define IF_ENABLED(_flag, _code) \
224224
COND_CODE_1(_flag, _code, ())
225225

226+
/**
227+
* @brief Insert code if @p _flag is not defined as 1.
228+
*
229+
* This expands to nothing if @p _flag is defined and equal to 1;
230+
* it expands to @p _code otherwise.
231+
*
232+
* Example:
233+
*
234+
* IF_DISABLED(CONFIG_FLAG, (uint32_t foo;))
235+
*
236+
* If @p CONFIG_FLAG isn't defined or different than 1, this expands to:
237+
*
238+
* uint32_t foo;
239+
*
240+
* and to nothing otherwise.
241+
*
242+
* IF_DISABLED does the opposite of IF_ENABLED.
243+
*
244+
* @param _flag evaluated flag
245+
* @param _code result if @p _flag does not expand to 1; must be in parentheses
246+
*/
247+
#define IF_DISABLED(_flag, _code) \
248+
COND_CODE_1(_flag, (), _code)
249+
226250
/**
227251
* @brief Check if a macro has a replacement expression
228252
*

0 commit comments

Comments
 (0)