/* * Copyright (c) 2011-2014, Wind River Systems, Inc. * Copyright (c) 2020, Nordic Semiconductor ASA * * SPDX-License-Identifier: Apache-2.0 */ /** * @file * @brief Misc utilities * * Repetitive or obscure helper macros needed by sys/util.h. */ #ifndef ZEPHYR_INCLUDE_SYS_UTIL_INTERNAL_H_ #define ZEPHYR_INCLUDE_SYS_UTIL_INTERNAL_H_ /* IS_ENABLED() helpers */ /* This is called from IS_ENABLED(), and sticks on a "_XXXX" prefix, * it will now be "_XXXX1" if config_macro is "1", or just "_XXXX" if it's * undefined. * ENABLED: Z_IS_ENABLED2(_XXXX1) * DISABLED Z_IS_ENABLED2(_XXXX) */ #define Z_IS_ENABLED1(config_macro) Z_IS_ENABLED2(_XXXX##config_macro) /* Here's the core trick, we map "_XXXX1" to "_YYYY," (i.e. a string * with a trailing comma), so it has the effect of making this a * two-argument tuple to the preprocessor only in the case where the * value is defined to "1" * ENABLED: _YYYY, <--- note comma! * DISABLED: _XXXX */ #define _XXXX1 _YYYY, /* Then we append an extra argument to fool the gcc preprocessor into * accepting it as a varargs macro. * arg1 arg2 arg3 * ENABLED: Z_IS_ENABLED3(_YYYY, 1, 0) * DISABLED Z_IS_ENABLED3(_XXXX 1, 0) */ #define Z_IS_ENABLED2(one_or_two_args) Z_IS_ENABLED3(one_or_two_args 1, 0) /* And our second argument is thus now cooked to be 1 in the case * where the value is defined to 1, and 0 if not: */ #define Z_IS_ENABLED3(ignore_this, val, ...) val #endif /* ZEPHYR_INCLUDE_SYS_UTIL_INTERNAL_H_ */