1 /* 2 * Copyright (c) 2011-2014, Wind River Systems, Inc. 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 /** 8 * @file 9 * @brief Macro utilities 10 * 11 * Macro utilities are the public interface for C/C++ code and device tree 12 * related implementation. In general, C/C++ will include <sys/util.h> 13 * instead this file directly. For device tree implementation, this file 14 * should be include instead <sys/util_internal.h> 15 */ 16 17 #ifndef ZEPHYR_INCLUDE_SYS_UTIL_MACROS_H_ 18 #define ZEPHYR_INCLUDE_SYS_UTIL_MACROS_H_ 19 20 #ifdef __cplusplus 21 extern "C" { 22 #endif 23 24 /** 25 * @addtogroup sys-util 26 * @{ 27 */ 28 29 /* 30 * Most of the eldritch implementation details for all the macrobatics 31 * below (APIs like IS_ENABLED(), COND_CODE_1(), etc.) are hidden away 32 * in this file. 33 */ 34 #include <zephyr/sys/util_internal.h> 35 36 #ifndef BIT 37 #if defined(_ASMLANGUAGE) 38 #define BIT(n) (1 << (n)) 39 #else 40 /** 41 * @brief Unsigned integer with bit position @p n set (signed in 42 * assembly language). 43 */ 44 #define BIT(n) (1UL << (n)) 45 #endif 46 #endif 47 48 /** @brief 64-bit unsigned integer with bit position @p _n set. */ 49 #define BIT64(_n) (1ULL << (_n)) 50 51 /** 52 * @brief Set or clear a bit depending on a boolean value 53 * 54 * The argument @p var is a variable whose value is written to as a 55 * side effect. 56 * 57 * @param var Variable to be altered 58 * @param bit Bit number 59 * @param set if 0, clears @p bit in @p var; any other value sets @p bit 60 */ 61 #define WRITE_BIT(var, bit, set) \ 62 ((var) = (set) ? ((var) | BIT(bit)) : ((var) & ~BIT(bit))) 63 64 /** 65 * @brief Bit mask with bits 0 through <tt>n-1</tt> (inclusive) set, 66 * or 0 if @p n is 0. 67 */ 68 #define BIT_MASK(n) (BIT(n) - 1UL) 69 70 /** 71 * @brief 64-bit bit mask with bits 0 through <tt>n-1</tt> (inclusive) set, 72 * or 0 if @p n is 0. 73 */ 74 #define BIT64_MASK(n) (BIT64(n) - 1ULL) 75 76 /** @brief Check if a @p x is a power of two */ 77 #define IS_POWER_OF_TWO(x) (((x) != 0U) && (((x) & ((x) - 1U)) == 0U)) 78 79 /** 80 * @brief Check if bits are set continuously from the specified bit 81 * 82 * The macro is not dependent on the bit-width. 83 * 84 * @param m Check whether the bits are set continuously or not. 85 * @param s Specify the lowest bit for that is continuously set bits. 86 */ 87 #define IS_SHIFTED_BIT_MASK(m, s) (!(((m) >> (s)) & (((m) >> (s)) + 1U))) 88 89 /** 90 * @brief Check if bits are set continuously from the LSB. 91 * 92 * @param m Check whether the bits are set continuously from LSB. 93 */ 94 #define IS_BIT_MASK(m) IS_SHIFTED_BIT_MASK(m, 0) 95 96 /** 97 * @brief Check for macro definition in compiler-visible expressions 98 * 99 * This trick was pioneered in Linux as the config_enabled() macro. It 100 * has the effect of taking a macro value that may be defined to "1" 101 * or may not be defined at all and turning it into a literal 102 * expression that can be handled by the C compiler instead of just 103 * the preprocessor. It is often used with a @p CONFIG_FOO macro which 104 * may be defined to 1 via Kconfig, or left undefined. 105 * 106 * That is, it works similarly to <tt>\#if defined(CONFIG_FOO)</tt> 107 * except that its expansion is a C expression. Thus, much <tt>\#ifdef</tt> 108 * usage can be replaced with equivalents like: 109 * 110 * if (IS_ENABLED(CONFIG_FOO)) { 111 * do_something_with_foo 112 * } 113 * 114 * This is cleaner since the compiler can generate errors and warnings 115 * for @p do_something_with_foo even when @p CONFIG_FOO is undefined. 116 * 117 * Note: Use of IS_ENABLED in a <tt>\#if</tt> statement is discouraged 118 * as it doesn't provide any benefit vs plain <tt>\#if defined()</tt> 119 * 120 * @param config_macro Macro to check 121 * @return 1 if @p config_macro is defined to 1, 0 otherwise (including 122 * if @p config_macro is not defined) 123 */ 124 #define IS_ENABLED(config_macro) Z_IS_ENABLED1(config_macro) 125 /* INTERNAL: the first pass above is just to expand any existing 126 * macros, we need the macro value to be e.g. a literal "1" at 127 * expansion time in the next macro, not "(1)", etc... Standard 128 * recursive expansion does not work. 129 */ 130 131 /** 132 * @brief Insert code depending on whether @p _flag expands to 1 or not. 133 * 134 * This relies on similar tricks as IS_ENABLED(), but as the result of 135 * @p _flag expansion, results in either @p _if_1_code or @p 136 * _else_code is expanded. 137 * 138 * To prevent the preprocessor from treating commas as argument 139 * separators, the @p _if_1_code and @p _else_code expressions must be 140 * inside brackets/parentheses: <tt>()</tt>. These are stripped away 141 * during macro expansion. 142 * 143 * Example: 144 * 145 * COND_CODE_1(CONFIG_FLAG, (uint32_t x;), (there_is_no_flag();)) 146 * 147 * If @p CONFIG_FLAG is defined to 1, this expands to: 148 * 149 * uint32_t x; 150 * 151 * It expands to <tt>there_is_no_flag();</tt> otherwise. 152 * 153 * This could be used as an alternative to: 154 * 155 * #if defined(CONFIG_FLAG) && (CONFIG_FLAG == 1) 156 * #define MAYBE_DECLARE(x) uint32_t x 157 * #else 158 * #define MAYBE_DECLARE(x) there_is_no_flag() 159 * #endif 160 * 161 * MAYBE_DECLARE(x); 162 * 163 * However, the advantage of COND_CODE_1() is that code is resolved in 164 * place where it is used, while the @p \#if method defines @p 165 * MAYBE_DECLARE on two lines and requires it to be invoked again on a 166 * separate line. This makes COND_CODE_1() more concise and also 167 * sometimes more useful when used within another macro's expansion. 168 * 169 * @note @p _flag can be the result of preprocessor expansion, e.g. 170 * an expression involving <tt>NUM_VA_ARGS_LESS_1(...)</tt>. 171 * However, @p _if_1_code is only expanded if @p _flag expands 172 * to the integer literal 1. Integer expressions that evaluate 173 * to 1, e.g. after doing some arithmetic, will not work. 174 * 175 * @param _flag evaluated flag 176 * @param _if_1_code result if @p _flag expands to 1; must be in parentheses 177 * @param _else_code result otherwise; must be in parentheses 178 */ 179 #define COND_CODE_1(_flag, _if_1_code, _else_code) \ 180 Z_COND_CODE_1(_flag, _if_1_code, _else_code) 181 182 /** 183 * @brief Like COND_CODE_1() except tests if @p _flag is 0. 184 * 185 * This is like COND_CODE_1(), except that it tests whether @p _flag 186 * expands to the integer literal 0. It expands to @p _if_0_code if 187 * so, and @p _else_code otherwise; both of these must be enclosed in 188 * parentheses. 189 * 190 * @param _flag evaluated flag 191 * @param _if_0_code result if @p _flag expands to 0; must be in parentheses 192 * @param _else_code result otherwise; must be in parentheses 193 * @see COND_CODE_1() 194 */ 195 #define COND_CODE_0(_flag, _if_0_code, _else_code) \ 196 Z_COND_CODE_0(_flag, _if_0_code, _else_code) 197 198 /** 199 * @brief Insert code if @p _flag is defined and equals 1. 200 * 201 * Like COND_CODE_1(), this expands to @p _code if @p _flag is defined to 1; 202 * it expands to nothing otherwise. 203 * 204 * Example: 205 * 206 * IF_ENABLED(CONFIG_FLAG, (uint32_t foo;)) 207 * 208 * If @p CONFIG_FLAG is defined to 1, this expands to: 209 * 210 * uint32_t foo; 211 * 212 * and to nothing otherwise. 213 * 214 * It can be considered as a more compact alternative to: 215 * 216 * #if defined(CONFIG_FLAG) && (CONFIG_FLAG == 1) 217 * uint32_t foo; 218 * #endif 219 * 220 * @param _flag evaluated flag 221 * @param _code result if @p _flag expands to 1; must be in parentheses 222 */ 223 #define IF_ENABLED(_flag, _code) \ 224 COND_CODE_1(_flag, _code, ()) 225 226 /** 227 * @brief Check if a macro has a replacement expression 228 * 229 * If @p a is a macro defined to a nonempty value, this will return 230 * true, otherwise it will return false. It only works with defined 231 * macros, so an additional @p \#ifdef test may be needed in some cases. 232 * 233 * This macro may be used with COND_CODE_1() and COND_CODE_0() while 234 * processing `__VA_ARGS__` to avoid processing empty arguments. 235 * 236 * Example: 237 * 238 * #define EMPTY 239 * #define NON_EMPTY 1 240 * #undef UNDEFINED 241 * IS_EMPTY(EMPTY) 242 * IS_EMPTY(NON_EMPTY) 243 * IS_EMPTY(UNDEFINED) 244 * #if defined(EMPTY) && IS_EMPTY(EMPTY) == true 245 * some_conditional_code 246 * #endif 247 * 248 * In above examples, the invocations of IS_EMPTY(...) return @p true, 249 * @p false, and @p true; @p some_conditional_code is included. 250 * 251 * @param ... macro to check for emptiness (may be `__VA_ARGS__`) 252 */ 253 #define IS_EMPTY(...) Z_IS_EMPTY_(__VA_ARGS__) 254 255 /** 256 * @brief Like <tt>a == b</tt>, but does evaluation and 257 * short-circuiting at C preprocessor time. 258 * 259 * This however only works for integer literal from 0 to 4095. 260 * 261 */ 262 #define IS_EQ(a, b) Z_IS_EQ(a, b) 263 264 /** 265 * @brief Remove empty arguments from list. 266 * 267 * During macro expansion, `__VA_ARGS__` and other preprocessor 268 * generated lists may contain empty elements, e.g.: 269 * 270 * #define LIST ,a,b,,d, 271 * 272 * Using EMPTY to show each empty element, LIST contains: 273 * 274 * EMPTY, a, b, EMPTY, d 275 * 276 * When processing such lists, e.g. using FOR_EACH(), all empty elements 277 * will be processed, and may require filtering out. 278 * To make that process easier, it is enough to invoke LIST_DROP_EMPTY 279 * which will remove all empty elements. 280 * 281 * Example: 282 * 283 * LIST_DROP_EMPTY(LIST) 284 * 285 * expands to: 286 * 287 * a, b, d 288 * 289 * @param ... list to be processed 290 */ 291 #define LIST_DROP_EMPTY(...) \ 292 Z_LIST_DROP_FIRST(FOR_EACH(Z_LIST_NO_EMPTIES, (), __VA_ARGS__)) 293 294 /** 295 * @brief Macro with an empty expansion 296 * 297 * This trivial definition is provided for readability when a macro 298 * should expand to an empty result, which e.g. is sometimes needed to 299 * silence checkpatch. 300 * 301 * Example: 302 * 303 * #define LIST_ITEM(n) , item##n 304 * 305 * The above would cause checkpatch to complain, but: 306 * 307 * #define LIST_ITEM(n) EMPTY, item##n 308 * 309 * would not. 310 */ 311 #define EMPTY 312 313 /** 314 * @brief Macro that expands to its argument 315 * 316 * This is useful in macros like @c FOR_EACH() when there is no 317 * transformation required on the list elements. 318 * 319 * @param V any value 320 */ 321 #define IDENTITY(V) V 322 323 /** 324 * @brief Get nth argument from argument list. 325 * 326 * @param N Argument index to fetch. Counter from 1. 327 * @param ... Variable list of arguments from which one argument is returned. 328 * 329 * @return Nth argument. 330 */ 331 #define GET_ARG_N(N, ...) Z_GET_ARG_##N(__VA_ARGS__) 332 333 /** 334 * @brief Strips n first arguments from the argument list. 335 * 336 * @param N Number of arguments to discard. 337 * @param ... Variable list of arguments. 338 * 339 * @return argument list without N first arguments. 340 */ 341 #define GET_ARGS_LESS_N(N, ...) Z_GET_ARGS_LESS_##N(__VA_ARGS__) 342 343 /** 344 * @brief Like <tt>a || b</tt>, but does evaluation and 345 * short-circuiting at C preprocessor time. 346 * 347 * This is not the same as the binary @p || operator; in particular, 348 * @p a should expand to an integer literal 0 or 1. However, @p b 349 * can be any value. 350 * 351 * This can be useful when @p b is an expression that would cause a 352 * build error when @p a is 1. 353 */ 354 #define UTIL_OR(a, b) COND_CODE_1(UTIL_BOOL(a), (a), (b)) 355 356 /** 357 * @brief Like <tt>a && b</tt>, but does evaluation and 358 * short-circuiting at C preprocessor time. 359 * 360 * This is not the same as the binary @p &&, however; in particular, 361 * @p a should expand to an integer literal 0 or 1. However, @p b 362 * can be any value. 363 * 364 * This can be useful when @p b is an expression that would cause a 365 * build error when @p a is 0. 366 */ 367 #define UTIL_AND(a, b) COND_CODE_1(UTIL_BOOL(a), (b), (0)) 368 369 /** 370 * @brief UTIL_INC(x) for an integer literal x from 0 to 4095 expands to an 371 * integer literal whose value is x+1. 372 * 373 * @see UTIL_DEC(x) 374 */ 375 #define UTIL_INC(x) UTIL_PRIMITIVE_CAT(Z_UTIL_INC_, x) 376 377 /** 378 * @brief UTIL_DEC(x) for an integer literal x from 0 to 4095 expands to an 379 * integer literal whose value is x-1. 380 * 381 * @see UTIL_INC(x) 382 */ 383 #define UTIL_DEC(x) UTIL_PRIMITIVE_CAT(Z_UTIL_DEC_, x) 384 385 /** 386 * @brief UTIL_X2(y) for an integer literal y from 0 to 4095 expands to an 387 * integer literal whose value is 2y. 388 */ 389 #define UTIL_X2(y) UTIL_PRIMITIVE_CAT(Z_UTIL_X2_, y) 390 391 392 /** 393 * @brief Generates a sequence of code with configurable separator. 394 * 395 * Example: 396 * 397 * #define FOO(i, _) MY_PWM ## i 398 * { LISTIFY(PWM_COUNT, FOO, (,)) } 399 * 400 * The above two lines expand to: 401 * 402 * { MY_PWM0 , MY_PWM1 } 403 * 404 * @param LEN The length of the sequence. Must be an integer literal less 405 * than 4095. 406 * @param F A macro function that accepts at least two arguments: 407 * <tt>F(i, ...)</tt>. @p F is called repeatedly in the expansion. 408 * Its first argument @p i is the index in the sequence, and 409 * the variable list of arguments passed to LISTIFY are passed 410 * through to @p F. 411 * 412 * @param sep Separator (e.g. comma or semicolon). Must be in parentheses; 413 * this is required to enable providing a comma as separator. 414 * 415 * @note Calling LISTIFY with undefined arguments has undefined 416 * behavior. 417 */ 418 #define LISTIFY(LEN, F, sep, ...) UTIL_CAT(Z_UTIL_LISTIFY_, LEN)(F, sep, __VA_ARGS__) 419 420 /** 421 * @brief Call a macro @p F on each provided argument with a given 422 * separator between each call. 423 * 424 * Example: 425 * 426 * #define F(x) int a##x 427 * FOR_EACH(F, (;), 4, 5, 6); 428 * 429 * This expands to: 430 * 431 * int a4; 432 * int a5; 433 * int a6; 434 * 435 * @param F Macro to invoke 436 * @param sep Separator (e.g. comma or semicolon). Must be in parentheses; 437 * this is required to enable providing a comma as separator. 438 * @param ... Variable argument list. The macro @p F is invoked as 439 * <tt>F(element)</tt> for each element in the list. 440 */ 441 #define FOR_EACH(F, sep, ...) \ 442 Z_FOR_EACH(F, sep, REVERSE_ARGS(__VA_ARGS__)) 443 444 /** 445 * @brief Like FOR_EACH(), but with a terminator instead of a separator, 446 * and drops empty elements from the argument list 447 * 448 * The @p sep argument to <tt>FOR_EACH(F, (sep), a, b)</tt> is a 449 * separator which is placed between calls to @p F, like this: 450 * 451 * FOR_EACH(F, (sep), a, b) // F(a) sep F(b) 452 * // ^^^ no sep here! 453 * 454 * By contrast, the @p term argument to <tt>FOR_EACH_NONEMPTY_TERM(F, (term), 455 * a, b)</tt> is added after each time @p F appears in the expansion: 456 * 457 * FOR_EACH_NONEMPTY_TERM(F, (term), a, b) // F(a) term F(b) term 458 * // ^^^^ 459 * 460 * Further, any empty elements are dropped: 461 * 462 * FOR_EACH_NONEMPTY_TERM(F, (term), a, EMPTY, b) // F(a) term F(b) term 463 * 464 * This is more convenient in some cases, because FOR_EACH_NONEMPTY_TERM() 465 * expands to nothing when given an empty argument list, and it's 466 * often cumbersome to write a macro @p F that does the right thing 467 * even when given an empty argument. 468 * 469 * One example is when `__VA_ARGS__` may or may not be empty, 470 * and the results are embedded in a larger initializer: 471 * 472 * #define SQUARE(x) ((x)*(x)) 473 * 474 * int my_array[] = { 475 * FOR_EACH_NONEMPTY_TERM(SQUARE, (,), FOO(...)) 476 * FOR_EACH_NONEMPTY_TERM(SQUARE, (,), BAR(...)) 477 * FOR_EACH_NONEMPTY_TERM(SQUARE, (,), BAZ(...)) 478 * }; 479 * 480 * This is more convenient than: 481 * 482 * 1. figuring out whether the @p FOO, @p BAR, and @p BAZ expansions 483 * are empty and adding a comma manually (or not) between FOR_EACH() 484 * calls 485 * 2. rewriting SQUARE so it reacts appropriately when "x" is empty 486 * (which would be necessary if e.g. @p FOO expands to nothing) 487 * 488 * @param F Macro to invoke on each nonempty element of the variable 489 * arguments 490 * @param term Terminator (e.g. comma or semicolon) placed after each 491 * invocation of F. Must be in parentheses; this is required 492 * to enable providing a comma as separator. 493 * @param ... Variable argument list. The macro @p F is invoked as 494 * <tt>F(element)</tt> for each nonempty element in the list. 495 */ 496 #define FOR_EACH_NONEMPTY_TERM(F, term, ...) \ 497 COND_CODE_0( \ 498 /* are there zero non-empty arguments ? */ \ 499 NUM_VA_ARGS_LESS_1(LIST_DROP_EMPTY(__VA_ARGS__, _)), \ 500 /* if so, expand to nothing */ \ 501 (), \ 502 /* otherwise, expand to: */ \ 503 (/* FOR_EACH() on nonempty elements, */ \ 504 FOR_EACH(F, term, LIST_DROP_EMPTY(__VA_ARGS__)) \ 505 /* plus a final terminator */ \ 506 __DEBRACKET term \ 507 )) 508 509 /** 510 * @brief Call macro @p F on each provided argument, with the argument's index 511 * as an additional parameter. 512 * 513 * This is like FOR_EACH(), except @p F should be a macro which takes two 514 * arguments: <tt>F(index, variable_arg)</tt>. 515 * 516 * Example: 517 * 518 * #define F(idx, x) int a##idx = x 519 * FOR_EACH_IDX(F, (;), 4, 5, 6); 520 * 521 * This expands to: 522 * 523 * int a0 = 4; 524 * int a1 = 5; 525 * int a2 = 6; 526 * 527 * @param F Macro to invoke 528 * @param sep Separator (e.g. comma or semicolon). Must be in parentheses; 529 * this is required to enable providing a comma as separator. 530 * @param ... Variable argument list. The macro @p F is invoked as 531 * <tt>F(index, element)</tt> for each element in the list. 532 */ 533 #define FOR_EACH_IDX(F, sep, ...) \ 534 Z_FOR_EACH_IDX(F, sep, REVERSE_ARGS(__VA_ARGS__)) 535 536 /** 537 * @brief Call macro @p F on each provided argument, with an additional fixed 538 * argument as a parameter. 539 * 540 * This is like FOR_EACH(), except @p F should be a macro which takes two 541 * arguments: <tt>F(variable_arg, fixed_arg)</tt>. 542 * 543 * Example: 544 * 545 * static void func(int val, void *dev); 546 * FOR_EACH_FIXED_ARG(func, (;), dev, 4, 5, 6); 547 * 548 * This expands to: 549 * 550 * func(4, dev); 551 * func(5, dev); 552 * func(6, dev); 553 * 554 * @param F Macro to invoke 555 * @param sep Separator (e.g. comma or semicolon). Must be in parentheses; 556 * this is required to enable providing a comma as separator. 557 * @param fixed_arg Fixed argument passed to @p F as the second macro parameter. 558 * @param ... Variable argument list. The macro @p F is invoked as 559 * <tt>F(element, fixed_arg)</tt> for each element in the list. 560 */ 561 #define FOR_EACH_FIXED_ARG(F, sep, fixed_arg, ...) \ 562 Z_FOR_EACH_FIXED_ARG(F, sep, fixed_arg, REVERSE_ARGS(__VA_ARGS__)) 563 564 /** 565 * @brief Calls macro @p F for each variable argument with an index and fixed 566 * argument 567 * 568 * This is like the combination of FOR_EACH_IDX() with FOR_EACH_FIXED_ARG(). 569 * 570 * Example: 571 * 572 * #define F(idx, x, fixed_arg) int fixed_arg##idx = x 573 * FOR_EACH_IDX_FIXED_ARG(F, (;), a, 4, 5, 6); 574 * 575 * This expands to: 576 * 577 * int a0 = 4; 578 * int a1 = 5; 579 * int a2 = 6; 580 * 581 * @param F Macro to invoke 582 * @param sep Separator (e.g. comma or semicolon). Must be in parentheses; 583 * This is required to enable providing a comma as separator. 584 * @param fixed_arg Fixed argument passed to @p F as the third macro parameter. 585 * @param ... Variable list of arguments. The macro @p F is invoked as 586 * <tt>F(index, element, fixed_arg)</tt> for each element in 587 * the list. 588 */ 589 #define FOR_EACH_IDX_FIXED_ARG(F, sep, fixed_arg, ...) \ 590 Z_FOR_EACH_IDX_FIXED_ARG(F, sep, fixed_arg, REVERSE_ARGS(__VA_ARGS__)) 591 592 /** @brief Reverse arguments order. 593 * 594 * @param ... Variable argument list. 595 */ 596 #define REVERSE_ARGS(...) \ 597 Z_FOR_EACH_ENGINE(Z_FOR_EACH_EXEC, (,), Z_BYPASS, _, __VA_ARGS__) 598 599 /** 600 * @brief Number of arguments in the variable arguments list minus one. 601 * 602 * @param ... List of arguments 603 * @return Number of variadic arguments in the argument list, minus one 604 */ 605 #define NUM_VA_ARGS_LESS_1(...) \ 606 NUM_VA_ARGS_LESS_1_IMPL(__VA_ARGS__, 63, 62, 61, \ 607 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, \ 608 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, \ 609 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, \ 610 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, \ 611 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, \ 612 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, ~) 613 614 /** 615 * @brief Mapping macro that pastes results together 616 * 617 * This is similar to FOR_EACH() in that it invokes a macro repeatedly 618 * on each element of `__VA_ARGS__`. However, unlike FOR_EACH(), 619 * MACRO_MAP_CAT() pastes the results together into a single token. 620 * 621 * For example, with this macro FOO: 622 * 623 * #define FOO(x) item_##x##_ 624 * 625 * <tt>MACRO_MAP_CAT(FOO, a, b, c),</tt> expands to the token: 626 * 627 * item_a_item_b_item_c_ 628 * 629 * @param ... Macro to expand on each argument, followed by its 630 * arguments. (The macro should take exactly one argument.) 631 * @return The results of expanding the macro on each argument, all pasted 632 * together 633 */ 634 #define MACRO_MAP_CAT(...) MACRO_MAP_CAT_(__VA_ARGS__) 635 636 /** 637 * @brief Mapping macro that pastes a fixed number of results together 638 * 639 * Similar to @ref MACRO_MAP_CAT(), but expects a fixed number of 640 * arguments. If more arguments are given than are expected, the rest 641 * are ignored. 642 * 643 * @param N Number of arguments to map 644 * @param ... Macro to expand on each argument, followed by its 645 * arguments. (The macro should take exactly one argument.) 646 * @return The results of expanding the macro on each argument, all pasted 647 * together 648 */ 649 #define MACRO_MAP_CAT_N(N, ...) MACRO_MAP_CAT_N_(N, __VA_ARGS__) 650 651 /** 652 * @} 653 */ 654 655 #ifdef __cplusplus 656 } 657 #endif 658 659 #endif /* ZEPHYR_INCLUDE_SYS_UTIL_MACROS_H_ */ 660