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 Misc utilities
10  *
11  * Misc utilities usable by the kernel and application code.
12  */
13 
14 #ifndef _UTIL__H_
15 #define _UTIL__H_
16 
17 #ifndef _ASMLANGUAGE
18 
19 #include <ble_types/types.h>
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23 
24 /* Helper to pass a int as a pointer or vice-versa. */
25 #define POINTER_TO_UINT(x) ((uintptr_t) (x))
26 #define UINT_TO_POINTER(x) ((void *) (uintptr_t) (x))
27 #define POINTER_TO_INT(x)  ((intptr_t) (x))
28 #define INT_TO_POINTER(x)  ((void *) (intptr_t) (x))
29 
30 #if !(defined (__CHAR_BIT__) && defined (__SIZEOF_LONG__))
31 #	error Missing required predefined macros for BITS_PER_LONG calculation
32 #endif
33 
34 #define BITS_PER_LONG	(__CHAR_BIT__ * __SIZEOF_LONG__)
35 /* Create a contiguous bitmask starting at bit position @l and ending at
36  * position @h.
37  */
38 #define GENMASK(h, l) \
39 	(((~0UL) - (1UL << (l)) + 1) & (~0UL >> (BITS_PER_LONG - 1 - (h))))
40 
41 /* Evaluates to 0 if cond is true-ish; compile error otherwise */
42 #define ZERO_OR_COMPILE_ERROR(cond) ((int) sizeof(char[1 - 2 * !(cond)]) - 1)
43 
44 /* Evaluates to 0 if array is an array; compile error if not array (e.g.
45  * pointer)
46  */
47 #define IS_ARRAY(array) \
48 	ZERO_OR_COMPILE_ERROR( \
49 		!__builtin_types_compatible_p(__typeof__(array), \
50 					      __typeof__(&(array)[0])))
51 
52 /* Evaluates to number of elements in an array; compile error if not
53  * an array (e.g. pointer)
54  */
55 #ifndef ARRAY_SIZE
56 #define ARRAY_SIZE(array) \
57 	((unsigned long) (IS_ARRAY(array) + \
58 		(sizeof(array) / sizeof((array)[0]))))
59 #endif
60 
61 /* Evaluates to 1 if ptr is part of array, 0 otherwise; compile error if
62  * "array" argument is not an array (e.g. "ptr" and "array" mixed up)
63  */
64 #define PART_OF_ARRAY(array, ptr) \
65 	((ptr) && ((ptr) >= &array[0] && (ptr) < &array[ARRAY_SIZE(array)]))
66 
67 #define CONTAINER_OF(ptr, type, field) \
68 	((type *)(((char *)(ptr)) - offsetof(type, field)))
69 
70 /* round "x" up/down to next multiple of "align" (which must be a power of 2) */
71 #define ROUND_UP(x, align)                                   \
72 	(((unsigned long)(x) + ((unsigned long)(align) - 1)) & \
73 	 ~((unsigned long)(align) - 1))
74 #define ROUND_DOWN(x, align)                                 \
75 	((unsigned long)(x) & ~((unsigned long)(align) - 1))
76 
77 /* round up/down to the next word boundary */
78 #define WB_UP(x) ROUND_UP(x, sizeof(void *))
79 #define WB_DN(x) ROUND_DOWN(x, sizeof(void *))
80 
81 #define ceiling_fraction(numerator, divider) \
82 	(((numerator) + ((divider) - 1)) / (divider))
83 
84 /** @brief Return larger value of two provided expressions.
85  *
86  * @note Arguments are evaluated twice. See Z_MAX for GCC only, single
87  * evaluation version.
88  */
89 #ifndef MAX
90 #define MAX(a, b) (((a) > (b)) ? (a) : (b))
91 #endif
92 
93 /** @brief Return smaller value of two provided expressions.
94  *
95  * @note Arguments are evaluated twice. See Z_MIN for GCC only, single
96  * evaluation version.
97  */
98 #ifndef MIN
99 #define MIN(a, b) (((a) < (b)) ? (a) : (b))
100 #endif
101 
is_power_of_two(unsigned int x)102 static inline bool is_power_of_two(unsigned int x)
103 {
104 	return (x != 0U) && ((x & (x - 1)) == 0U);
105 }
106 
arithmetic_shift_right(s64_t value,u8_t shift)107 static inline s64_t arithmetic_shift_right(s64_t value, u8_t shift)
108 {
109 	s64_t sign_ext;
110 
111 	if (shift == 0U) {
112 		return value;
113 	}
114 
115 	/* extract sign bit */
116 	sign_ext = (value >> 63) & 1;
117 
118 	/* make all bits of sign_ext be the same as the value's sign bit */
119 	sign_ext = -sign_ext;
120 
121 	/* shift value and fill opened bit positions with sign bit */
122 	return (value >> shift) | (sign_ext << (64 - shift));
123 }
124 
125 /**
126  * @brief      Convert a single character into a hexadecimal nibble.
127  *
128  * @param[in]  c     The character to convert
129  * @param      x     The address of storage for the converted number.
130  *
131  *  @return Zero on success or (negative) error code otherwise.
132  */
133 int char2hex(char c, u8_t *x);
134 
135 /**
136  * @brief      Convert a single hexadecimal nibble into a character.
137  *
138  * @param[in]  c     The number to convert
139  * @param      x     The address of storage for the converted character.
140  *
141  *  @return Zero on success or (negative) error code otherwise.
142  */
143 int hex2char(u8_t x, char *c);
144 
145 /**
146  * @brief      Convert a binary array into string representation.
147  *
148  * @param[in]  buf     The binary array to convert
149  * @param[in]  buflen  The length of the binary array to convert
150  * @param[out] hex     Address of where to store the string representation.
151  * @param[in]  hexlen  Size of the storage area for string representation.
152  *
153  * @return     The length of the converted string, or 0 if an error occurred.
154  */
155 size_t bin2hex(const u8_t *buf, size_t buflen, char *hex, size_t hexlen);
156 
157 /*
158  * Convert hex string to byte string
159  * Return number of bytes written to buf, or 0 on error
160  * @return     The length of the converted array, or 0 if an error occurred.
161  */
162 
163 /**
164  * @brief      Convert a hexadecimal string into a binary array.
165  *
166  * @param[in]  hex     The hexadecimal string to convert
167  * @param[in]  hexlen  The length of the hexadecimal string to convert.
168  * @param[out] buf     Address of where to store the binary data
169  * @param[in]  buflen  Size of the storage area for binary data
170  *
171  * @return     The length of the binary array , or 0 if an error occurred.
172  */
173 size_t hex2bin(const char *hex, size_t hexlen, u8_t *buf, size_t buflen);
174 
175 /**
176  * @brief      Convert a u8_t into decimal string representation.
177  *
178  * Convert a u8_t value into ASCII decimal string representation.
179  * The string is terminated if there is enough space in buf.
180  *
181  * @param[out] buf     Address of where to store the string representation.
182  * @param[in]  buflen  Size of the storage area for string representation.
183  * @param[in]  value   The value to convert to decimal string
184  *
185  * @return     The length of the converted string (excluding terminator if
186  *             any), or 0 if an error occurred.
187  */
188 u8_t u8_to_dec(char *buf, u8_t buflen, u8_t value);
189 
190 #endif /* !_ASMLANGUAGE */
191 
192 /* KB, MB, GB */
193 #define KB(x) ((x) << 10)
194 #define MB(x) (KB(x) << 10)
195 #define GB(x) (MB(x) << 10)
196 
197 /* KHZ, MHZ */
198 #define KHZ(x) ((x) * 1000)
199 #define MHZ(x) (KHZ(x) * 1000)
200 
201 #ifndef BIT
202 #if defined(_ASMLANGUAGE)
203 #define BIT(n)  (1 << (n))
204 #else
205 #define BIT(n)  (1UL << (n))
206 #endif
207 #endif
208 
209 /** 64-bit unsigned integer with bit position _n set */
210 #define BIT64(_n) (1ULL << (_n))
211 
212 /**
213  * @brief Macro sets or clears bit depending on boolean value
214  *
215  * @param var Variable to be altered
216  * @param bit Bit number
217  * @param set Value 0 clears bit, any other value sets bit
218  */
219 #define WRITE_BIT(var, bit, set) \
220 	((var) = (set) ? ((var) | BIT(bit)) : ((var) & ~BIT(bit)))
221 
222 #define BIT_MASK(n) (BIT(n) - 1)
223 
224 /**
225  * @brief Check for macro definition in compiler-visible expressions
226  *
227  * This trick was pioneered in Linux as the config_enabled() macro.
228  * The madness has the effect of taking a macro value that may be
229  * defined to "1" (e.g. CONFIG_MYFEATURE), or may not be defined at
230  * all and turning it into a literal expression that can be used at
231  * "runtime".  That is, it works similarly to
232  * "defined(CONFIG_MYFEATURE)" does except that it is an expansion
233  * that can exist in a standard expression and be seen by the compiler
234  * and optimizer.  Thus much ifdef usage can be replaced with cleaner
235  * expressions like:
236  *
237  *     if (IS_ENABLED(CONFIG_MYFEATURE))
238  *             myfeature_enable();
239  *
240  * INTERNAL
241  * First pass just to expand any existing macros, we need the macro
242  * value to be e.g. a literal "1" at expansion time in the next macro,
243  * not "(1)", etc...  Standard recursive expansion does not work.
244  */
245 #define IS_ENABLED(config_macro) Z_IS_ENABLED1(config_macro)
246 
247 /* Now stick on a "_XXXX" prefix, it will now be "_XXXX1" if config_macro
248  * is "1", or just "_XXXX" if it's undefined.
249  *   ENABLED:   Z_IS_ENABLED2(_XXXX1)
250  *   DISABLED   Z_IS_ENABLED2(_XXXX)
251  */
252 #define Z_IS_ENABLED1(config_macro) Z_IS_ENABLED2(_XXXX##config_macro)
253 
254 /* Here's the core trick, we map "_XXXX1" to "_YYYY," (i.e. a string
255  * with a trailing comma), so it has the effect of making this a
256  * two-argument tuple to the preprocessor only in the case where the
257  * value is defined to "1"
258  *   ENABLED:    _YYYY,    <--- note comma!
259  *   DISABLED:   _XXXX
260  */
261 #define _XXXX1 _YYYY,
262 
263 /* Then we append an extra argument to fool the gcc preprocessor into
264  * accepting it as a varargs macro.
265  *                         arg1   arg2  arg3
266  *   ENABLED:   Z_IS_ENABLED3(_YYYY,    1,    0)
267  *   DISABLED   Z_IS_ENABLED3(_XXXX 1,  0)
268  */
269 #define Z_IS_ENABLED2(one_or_two_args) Z_IS_ENABLED3(one_or_two_args true, false)
270 
271 /* And our second argument is thus now cooked to be 1 in the case
272  * where the value is defined to 1, and 0 if not:
273  */
274 #define Z_IS_ENABLED3(ignore_this, val, ...) val
275 
276 /**
277  * @brief Insert code depending on result of flag evaluation.
278  *
279  * This is based on same idea as @ref IS_ENABLED macro but as the result of
280  * flag evaluation provided code is injected. Because preprocessor interprets
281  * each comma as an argument boundary, code must be provided in the brackets.
282  * Brackets are stripped away during macro processing.
283  *
284  * Usage example:
285  *
286  * \#define MACRO(x) COND_CODE_1(CONFIG_FLAG, (bt_u32_t x;), ())
287  *
288  * It can be considered as alternative to:
289  *
290  * \#if defined(CONFIG_FLAG) && (CONFIG_FLAG == 1)
291  * \#define MACRO(x) bt_u32_t x;
292  * \#else
293  * \#define MACRO(x)
294  * \#endif
295  *
296  * However, the advantage of that approach is that code is resolved in place
297  * where it is used while \#if method resolves given macro when header is
298  * included and product is fixed in the given scope.
299  *
300  * @note Flag can also be a result of preprocessor output e.g.
301  *	 product of NUM_VA_ARGS_LESS_1(...).
302  *
303  * @param _flag		Evaluated flag
304  * @param _if_1_code	Code used if flag exists and equal 1. Argument must be
305  *			in brackets.
306  * @param _else_code	Code used if flag doesn't exists or isn't equal 1.
307  *
308  */
309 #define COND_CODE_1(_flag, _if_1_code, _else_code) \
310 	Z_COND_CODE_1(_flag, _if_1_code, _else_code)
311 
312 #define Z_COND_CODE_1(_flag, _if_1_code, _else_code) \
313 	__COND_CODE(_XXXX##_flag, _if_1_code, _else_code)
314 
315 /**
316  * @brief Insert code if flag is defined and equals 1.
317  *
318  * Usage example:
319  *
320  * IF_ENABLED(CONFIG_FLAG, (bt_u32_t foo;))
321  *
322  * It can be considered as more compact alternative to:
323  *
324  * \#if defined(CONFIG_FLAG) && (CONFIG_FLAG == 1)
325  *	bt_u32_t foo;
326  * \#endif
327  *
328  * @param _flag		Evaluated flag
329  * @param _code		Code used if flag exists and equal 1. Argument must be
330  *			in brackets.
331  */
332 #define IF_ENABLED(_flag, _code) \
333 	COND_CODE_1(_flag, _code, ())
334 
335 
336 /**
337  * @brief Check if defined name does have replacement string.
338  *
339  * If defined macro has value this will return true, otherwise
340  * it will return false. It only works with defined macros, so additional
341  * test (if defined) may be needed in some cases.
342  *
343  * This macro may be used, with COND_CODE_* macros, while processing
344  * __VA_ARG__ to avoid processing empty arguments.
345  *
346  * Note that this macro is indented to check macro names that evaluate
347  * to replacement lists being empty or containing numbers or macro name
348  * like tokens.
349  *
350  * Example:
351  *
352  *	#define EMPTY
353  *	#define NON_EMPTY	1
354  *	#undef  UNDEFINED
355  *	IS_EMPTY(EMPTY)
356  *	IS_EMPTY(NON_EMPTY)
357  *	IS_EMPTY(UNDEFINED)
358  *	#if defined(EMPTY) && IS_EMPTY(EMPTY) == true
359  *	...
360  *	#endif
361  *
362  * In above examples, the invocations of IS_EMPTY(...) will return: true,
363  * false, true and conditional code will be included.
364  *
365  * @param a		Makro to check
366  */
367 #define IS_EMPTY(a) Z_IS_EMPTY_(a, true, false,)
368 #define Z_IS_EMPTY_(...) Z_IS_EMPTY__(__VA_ARGS__)
369 #define Z_IS_EMPTY__(a, ...) Z_IS_EMPTY___(_ZZ##a##ZZ0, __VA_ARGS__)
370 #define Z_IS_EMPTY___(...) Z_IS_EMPTY____(GET_ARGS_LESS_1(__VA_ARGS__))
371 #define Z_IS_EMPTY____(...) GET_ARG2(__VA_ARGS__)
372 
373 /**
374  * @brief Remove empty arguments from list.
375  *
376  * Due to evaluation, __VA_ARGS__ and other preprocessor generated lists
377  * may contain empty elements, e.g.:
378  *
379  *	#define LIST ,a,b,,d,
380  *
381  * In above example the first, the element between b and d, and the last
382  * are empty.
383  * When processing such lists, by for-each type loops, all empty elements
384  * will be processed, and may require filtering out within a loop.
385  * To make that process easier, it is enough to invoke LIST_DROP_EMPTY
386  * which will remove all empty elements from list.
387  *
388  * Example:
389  *	LIST_DROP_EMPTY(list)
390  * will return:
391  *	a,b,d
392  * Notice that ',' are preceded by space.
393  *
394  * @param ... 		list to be processed
395  */
396 #define LIST_DROP_EMPTY(...) \
397 	Z_LIST_DROP_FIRST(FOR_EACH(Z_LIST_NO_EMPTIES, __VA_ARGS__))
398 
399 /* Adding ',' after each element would add empty element at the end of
400  * list, which is hard to remove, so instead precede each element with ',',
401  * this way first element is empty, and this one is easy to drop.
402  */
403 #define Z_LIST_ADD_ELEM(e) EMPTY, e
404 #define Z_LIST_DROP_FIRST(...) GET_ARGS_LESS_1(__VA_ARGS__)
405 #define Z_LIST_NO_EMPTIES(e) \
406 	COND_CODE_1(IS_EMPTY(e), (), (Z_LIST_ADD_ELEM(e)))
407 
408 
409 /**
410  * @brief Insert code depending on result of flag evaluation.
411  *
412  * See @ref COND_CODE_1 for details.
413  *
414  * @param _flag		Evaluated flag
415  * @param _if_0_code	Code used if flag exists and equal 0. Argument must be
416  *			in brackets.
417  * @param _else_code	Code used if flag doesn't exists or isn't equal 0.
418  *
419  */
420 #define COND_CODE_0(_flag, _if_0_code, _else_code) \
421 	Z_COND_CODE_0(_flag, _if_0_code, _else_code)
422 
423 #define Z_COND_CODE_0(_flag, _if_0_code, _else_code) \
424 	__COND_CODE(_ZZZZ##_flag, _if_0_code, _else_code)
425 
426 #define _ZZZZ0 _YYYY,
427 
428 /* Macro used internally by @ref COND_CODE_1 and @ref COND_CODE_0. */
429 #define __COND_CODE(one_or_two_args, _if_code, _else_code) \
430 	__GET_ARG2_DEBRACKET(one_or_two_args _if_code, _else_code)
431 
432 /* Macro used internally to remove brackets from argument. */
433 #define __DEBRACKET(...) __VA_ARGS__
434 
435 /* Macro used internally for getting second argument and removing brackets
436  * around that argument. It is expected that parameter is provided in brackets
437  */
438 #define __GET_ARG2_DEBRACKET(ignore_this, val, ...) __DEBRACKET val
439 
440 /**
441  * @brief Macro with empty replacement list
442  *
443  * This trivial definition is provided to use where macro is expected
444  * to evaluate to empty replacement string or when it is needed to
445  * cheat checkpatch.
446  *
447  * Examples
448  *
449  *	#define LIST_ITEM(n) , item##n
450  *
451  * would cause error with checkpatch, but:
452  *
453  *	#define LIST_TIEM(n) EMPTY, item##m
454  *
455  * would not.
456  */
457 #define EMPTY
458 
459 /**
460  * @brief Get first argument from variable list of arguments
461  */
462 #define GET_ARG1(arg1, ...) arg1
463 
464 /**
465  * @brief Get second argument from variable list of arguments
466  */
467 #define GET_ARG2(arg1, arg2, ...) arg2
468 
469 /**
470  * @brief Get all arguments except the first one.
471  */
472 #define GET_ARGS_LESS_1(val, ...) __VA_ARGS__
473 
474 /**
475  * Macros for doing code-generation with the preprocessor.
476  *
477  * Generally it is better to generate code with the preprocessor than
478  * to copy-paste code or to generate code with the build system /
479  * python script's etc.
480  *
481  * http://stackoverflow.com/a/12540675
482  */
483 #define UTIL_EMPTY(...)
484 #define UTIL_DEFER(...) __VA_ARGS__ UTIL_EMPTY()
485 #define UTIL_OBSTRUCT(...) __VA_ARGS__ UTIL_DEFER(UTIL_EMPTY)()
486 #define UTIL_EXPAND(...) __VA_ARGS__
487 
488 #define UTIL_EVAL(...)  UTIL_EVAL1(UTIL_EVAL1(UTIL_EVAL1(__VA_ARGS__)))
489 #define UTIL_EVAL1(...) UTIL_EVAL2(UTIL_EVAL2(UTIL_EVAL2(__VA_ARGS__)))
490 #define UTIL_EVAL2(...) UTIL_EVAL3(UTIL_EVAL3(UTIL_EVAL3(__VA_ARGS__)))
491 #define UTIL_EVAL3(...) UTIL_EVAL4(UTIL_EVAL4(UTIL_EVAL4(__VA_ARGS__)))
492 #define UTIL_EVAL4(...) UTIL_EVAL5(UTIL_EVAL5(UTIL_EVAL5(__VA_ARGS__)))
493 #define UTIL_EVAL5(...) __VA_ARGS__
494 
495 #define UTIL_CAT(a, ...) UTIL_PRIMITIVE_CAT(a, __VA_ARGS__)
496 #define UTIL_PRIMITIVE_CAT(a, ...) a##__VA_ARGS__
497 
498 #define UTIL_INC(x) UTIL_PRIMITIVE_CAT(UTIL_INC_, x)
499 #define UTIL_INC_0 1
500 #define UTIL_INC_1 2
501 #define UTIL_INC_2 3
502 #define UTIL_INC_3 4
503 #define UTIL_INC_4 5
504 #define UTIL_INC_5 6
505 #define UTIL_INC_6 7
506 #define UTIL_INC_7 8
507 #define UTIL_INC_8 9
508 #define UTIL_INC_9 10
509 #define UTIL_INC_10 11
510 #define UTIL_INC_11 12
511 #define UTIL_INC_12 13
512 #define UTIL_INC_13 14
513 #define UTIL_INC_14 15
514 #define UTIL_INC_15 16
515 #define UTIL_INC_16 17
516 #define UTIL_INC_17 18
517 #define UTIL_INC_18 19
518 #define UTIL_INC_19 20
519 #define UTIL_INC_20 21
520 #define UTIL_INC_21 22
521 #define UTIL_INC_22 23
522 #define UTIL_INC_23 24
523 #define UTIL_INC_24 25
524 #define UTIL_INC_25 26
525 #define UTIL_INC_26 27
526 #define UTIL_INC_27 28
527 #define UTIL_INC_28 29
528 #define UTIL_INC_29 30
529 #define UTIL_INC_30 31
530 #define UTIL_INC_31 32
531 #define UTIL_INC_32 33
532 #define UTIL_INC_33 34
533 #define UTIL_INC_34 35
534 #define UTIL_INC_35 36
535 #define UTIL_INC_36 37
536 #define UTIL_INC_37 38
537 #define UTIL_INC_38 39
538 #define UTIL_INC_39 40
539 #define UTIL_INC_40 41
540 #define UTIL_INC_41 42
541 #define UTIL_INC_42 43
542 #define UTIL_INC_43 44
543 #define UTIL_INC_44 45
544 #define UTIL_INC_45 46
545 #define UTIL_INC_46 47
546 #define UTIL_INC_47 48
547 #define UTIL_INC_48 49
548 #define UTIL_INC_49 50
549 #define UTIL_INC_50 51
550 #define UTIL_INC_51 52
551 #define UTIL_INC_52 53
552 #define UTIL_INC_53 54
553 #define UTIL_INC_54 55
554 #define UTIL_INC_55 56
555 #define UTIL_INC_56 57
556 #define UTIL_INC_57 58
557 #define UTIL_INC_58 59
558 #define UTIL_INC_59 60
559 #define UTIL_INC_50 51
560 #define UTIL_INC_51 52
561 #define UTIL_INC_52 53
562 #define UTIL_INC_53 54
563 #define UTIL_INC_54 55
564 #define UTIL_INC_55 56
565 #define UTIL_INC_56 57
566 #define UTIL_INC_57 58
567 #define UTIL_INC_58 59
568 #define UTIL_INC_59 60
569 #define UTIL_INC_60 61
570 #define UTIL_INC_61 62
571 #define UTIL_INC_62 63
572 #define UTIL_INC_63 64
573 #define UTIL_INC_64 65
574 #define UTIL_INC_65 66
575 #define UTIL_INC_66 67
576 #define UTIL_INC_67 68
577 #define UTIL_INC_68 69
578 #define UTIL_INC_69 70
579 #define UTIL_INC_70 71
580 #define UTIL_INC_71 72
581 #define UTIL_INC_72 73
582 #define UTIL_INC_73 74
583 #define UTIL_INC_74 75
584 #define UTIL_INC_75 76
585 #define UTIL_INC_76 77
586 #define UTIL_INC_77 78
587 #define UTIL_INC_78 79
588 #define UTIL_INC_79 80
589 #define UTIL_INC_80 81
590 #define UTIL_INC_81 82
591 #define UTIL_INC_82 83
592 #define UTIL_INC_83 84
593 #define UTIL_INC_84 85
594 #define UTIL_INC_85 86
595 #define UTIL_INC_86 87
596 #define UTIL_INC_87 88
597 #define UTIL_INC_88 89
598 #define UTIL_INC_89 90
599 #define UTIL_INC_90 91
600 #define UTIL_INC_91 92
601 #define UTIL_INC_92 93
602 #define UTIL_INC_93 94
603 #define UTIL_INC_94 95
604 #define UTIL_INC_95 96
605 #define UTIL_INC_96 97
606 #define UTIL_INC_97 98
607 #define UTIL_INC_98 99
608 #define UTIL_INC_99 100
609 
610 #define UTIL_DEC(x) UTIL_PRIMITIVE_CAT(UTIL_DEC_, x)
611 #define UTIL_DEC_0 0
612 #define UTIL_DEC_1 0
613 #define UTIL_DEC_2 1
614 #define UTIL_DEC_3 2
615 #define UTIL_DEC_4 3
616 #define UTIL_DEC_5 4
617 #define UTIL_DEC_6 5
618 #define UTIL_DEC_7 6
619 #define UTIL_DEC_8 7
620 #define UTIL_DEC_9 8
621 #define UTIL_DEC_10 9
622 #define UTIL_DEC_11 10
623 #define UTIL_DEC_12 11
624 #define UTIL_DEC_13 12
625 #define UTIL_DEC_14 13
626 #define UTIL_DEC_15 14
627 #define UTIL_DEC_16 15
628 #define UTIL_DEC_17 16
629 #define UTIL_DEC_18 17
630 #define UTIL_DEC_19 18
631 #define UTIL_DEC_20 19
632 #define UTIL_DEC_21 20
633 #define UTIL_DEC_22 21
634 #define UTIL_DEC_23 22
635 #define UTIL_DEC_24 23
636 #define UTIL_DEC_25 24
637 #define UTIL_DEC_26 25
638 #define UTIL_DEC_27 26
639 #define UTIL_DEC_28 27
640 #define UTIL_DEC_29 28
641 #define UTIL_DEC_30 29
642 #define UTIL_DEC_31 30
643 #define UTIL_DEC_32 31
644 #define UTIL_DEC_33 32
645 #define UTIL_DEC_34 33
646 #define UTIL_DEC_35 34
647 #define UTIL_DEC_36 35
648 #define UTIL_DEC_37 36
649 #define UTIL_DEC_38 37
650 #define UTIL_DEC_39 38
651 #define UTIL_DEC_40 39
652 #define UTIL_DEC_41 40
653 #define UTIL_DEC_42 41
654 #define UTIL_DEC_43 42
655 #define UTIL_DEC_44 43
656 #define UTIL_DEC_45 44
657 #define UTIL_DEC_46 45
658 #define UTIL_DEC_47 46
659 #define UTIL_DEC_48 47
660 #define UTIL_DEC_49 48
661 #define UTIL_DEC_50 49
662 #define UTIL_DEC_51 50
663 #define UTIL_DEC_52 51
664 #define UTIL_DEC_53 52
665 #define UTIL_DEC_54 53
666 #define UTIL_DEC_55 54
667 #define UTIL_DEC_56 55
668 #define UTIL_DEC_57 56
669 #define UTIL_DEC_58 57
670 #define UTIL_DEC_59 58
671 #define UTIL_DEC_60 59
672 #define UTIL_DEC_61 60
673 #define UTIL_DEC_62 61
674 #define UTIL_DEC_63 62
675 #define UTIL_DEC_64 63
676 #define UTIL_DEC_65 64
677 #define UTIL_DEC_66 65
678 #define UTIL_DEC_67 66
679 #define UTIL_DEC_68 67
680 #define UTIL_DEC_69 68
681 #define UTIL_DEC_70 69
682 #define UTIL_DEC_71 70
683 #define UTIL_DEC_72 71
684 #define UTIL_DEC_73 72
685 #define UTIL_DEC_74 73
686 #define UTIL_DEC_75 74
687 #define UTIL_DEC_76 75
688 #define UTIL_DEC_77 76
689 #define UTIL_DEC_78 77
690 #define UTIL_DEC_79 78
691 #define UTIL_DEC_80 79
692 #define UTIL_DEC_81 80
693 #define UTIL_DEC_82 81
694 #define UTIL_DEC_83 82
695 #define UTIL_DEC_84 83
696 #define UTIL_DEC_85 84
697 #define UTIL_DEC_86 85
698 #define UTIL_DEC_87 86
699 #define UTIL_DEC_88 87
700 #define UTIL_DEC_89 88
701 #define UTIL_DEC_90 89
702 #define UTIL_DEC_91 90
703 #define UTIL_DEC_92 91
704 #define UTIL_DEC_93 92
705 #define UTIL_DEC_94 93
706 #define UTIL_DEC_95 94
707 #define UTIL_DEC_96 95
708 #define UTIL_DEC_97 96
709 #define UTIL_DEC_98 97
710 #define UTIL_DEC_99 98
711 #define UTIL_DEC_100 99
712 #define UTIL_DEC_101 100
713 #define UTIL_DEC_102 101
714 #define UTIL_DEC_103 102
715 #define UTIL_DEC_104 103
716 #define UTIL_DEC_105 104
717 #define UTIL_DEC_106 105
718 #define UTIL_DEC_107 106
719 #define UTIL_DEC_108 107
720 #define UTIL_DEC_109 108
721 #define UTIL_DEC_110 109
722 #define UTIL_DEC_111 110
723 #define UTIL_DEC_112 111
724 #define UTIL_DEC_113 112
725 #define UTIL_DEC_114 113
726 #define UTIL_DEC_115 114
727 #define UTIL_DEC_116 115
728 #define UTIL_DEC_117 116
729 #define UTIL_DEC_118 117
730 #define UTIL_DEC_119 118
731 #define UTIL_DEC_120 119
732 #define UTIL_DEC_121 120
733 #define UTIL_DEC_122 121
734 #define UTIL_DEC_123 122
735 #define UTIL_DEC_124 123
736 #define UTIL_DEC_125 124
737 #define UTIL_DEC_126 125
738 #define UTIL_DEC_127 126
739 #define UTIL_DEC_128 127
740 #define UTIL_DEC_129 128
741 #define UTIL_DEC_130 129
742 #define UTIL_DEC_131 130
743 #define UTIL_DEC_132 131
744 #define UTIL_DEC_133 132
745 #define UTIL_DEC_134 133
746 #define UTIL_DEC_135 134
747 #define UTIL_DEC_136 135
748 #define UTIL_DEC_137 136
749 #define UTIL_DEC_138 137
750 #define UTIL_DEC_139 138
751 #define UTIL_DEC_140 139
752 #define UTIL_DEC_141 140
753 #define UTIL_DEC_142 141
754 #define UTIL_DEC_143 142
755 #define UTIL_DEC_144 143
756 #define UTIL_DEC_145 144
757 #define UTIL_DEC_146 145
758 #define UTIL_DEC_147 146
759 #define UTIL_DEC_148 147
760 #define UTIL_DEC_149 148
761 #define UTIL_DEC_150 149
762 #define UTIL_DEC_151 150
763 #define UTIL_DEC_152 151
764 #define UTIL_DEC_153 152
765 #define UTIL_DEC_154 153
766 #define UTIL_DEC_155 154
767 #define UTIL_DEC_156 155
768 #define UTIL_DEC_157 156
769 #define UTIL_DEC_158 157
770 #define UTIL_DEC_159 158
771 #define UTIL_DEC_160 159
772 #define UTIL_DEC_161 160
773 #define UTIL_DEC_162 161
774 #define UTIL_DEC_163 162
775 #define UTIL_DEC_164 163
776 #define UTIL_DEC_165 164
777 #define UTIL_DEC_166 165
778 #define UTIL_DEC_167 166
779 #define UTIL_DEC_168 167
780 #define UTIL_DEC_169 168
781 #define UTIL_DEC_170 169
782 #define UTIL_DEC_171 170
783 #define UTIL_DEC_172 171
784 #define UTIL_DEC_173 172
785 #define UTIL_DEC_174 173
786 #define UTIL_DEC_175 174
787 #define UTIL_DEC_176 175
788 #define UTIL_DEC_177 176
789 #define UTIL_DEC_178 177
790 #define UTIL_DEC_179 178
791 #define UTIL_DEC_180 179
792 #define UTIL_DEC_181 180
793 #define UTIL_DEC_182 181
794 #define UTIL_DEC_183 182
795 #define UTIL_DEC_184 183
796 #define UTIL_DEC_185 184
797 #define UTIL_DEC_186 185
798 #define UTIL_DEC_187 186
799 #define UTIL_DEC_188 187
800 #define UTIL_DEC_189 188
801 #define UTIL_DEC_190 189
802 #define UTIL_DEC_191 190
803 #define UTIL_DEC_192 191
804 #define UTIL_DEC_193 192
805 #define UTIL_DEC_194 193
806 #define UTIL_DEC_195 194
807 #define UTIL_DEC_196 195
808 #define UTIL_DEC_197 196
809 #define UTIL_DEC_198 197
810 #define UTIL_DEC_199 198
811 #define UTIL_DEC_200 199
812 #define UTIL_DEC_201 200
813 #define UTIL_DEC_202 201
814 #define UTIL_DEC_203 202
815 #define UTIL_DEC_204 203
816 #define UTIL_DEC_205 204
817 #define UTIL_DEC_206 205
818 #define UTIL_DEC_207 206
819 #define UTIL_DEC_208 207
820 #define UTIL_DEC_209 208
821 #define UTIL_DEC_210 209
822 #define UTIL_DEC_211 210
823 #define UTIL_DEC_212 211
824 #define UTIL_DEC_213 212
825 #define UTIL_DEC_214 213
826 #define UTIL_DEC_215 214
827 #define UTIL_DEC_216 215
828 #define UTIL_DEC_217 216
829 #define UTIL_DEC_218 217
830 #define UTIL_DEC_219 218
831 #define UTIL_DEC_220 219
832 #define UTIL_DEC_221 220
833 #define UTIL_DEC_222 221
834 #define UTIL_DEC_223 222
835 #define UTIL_DEC_224 223
836 #define UTIL_DEC_225 224
837 #define UTIL_DEC_226 225
838 #define UTIL_DEC_227 226
839 #define UTIL_DEC_228 227
840 #define UTIL_DEC_229 228
841 #define UTIL_DEC_230 229
842 #define UTIL_DEC_231 230
843 #define UTIL_DEC_232 231
844 #define UTIL_DEC_233 232
845 #define UTIL_DEC_234 233
846 #define UTIL_DEC_235 234
847 #define UTIL_DEC_236 235
848 #define UTIL_DEC_237 236
849 #define UTIL_DEC_238 237
850 #define UTIL_DEC_239 238
851 #define UTIL_DEC_240 239
852 #define UTIL_DEC_241 240
853 #define UTIL_DEC_242 241
854 #define UTIL_DEC_243 242
855 #define UTIL_DEC_244 243
856 #define UTIL_DEC_245 244
857 #define UTIL_DEC_246 245
858 #define UTIL_DEC_247 246
859 #define UTIL_DEC_248 247
860 #define UTIL_DEC_249 248
861 #define UTIL_DEC_250 249
862 #define UTIL_DEC_251 250
863 #define UTIL_DEC_252 251
864 #define UTIL_DEC_253 252
865 #define UTIL_DEC_254 253
866 #define UTIL_DEC_255 254
867 #define UTIL_DEC_256 255
868 
869 #define UTIL_CHECK_N(x, n, ...) n
870 #define UTIL_CHECK(...) UTIL_CHECK_N(__VA_ARGS__, 0,)
871 
872 #define UTIL_NOT(x) UTIL_CHECK(UTIL_PRIMITIVE_CAT(UTIL_NOT_, x))
873 #define UTIL_NOT_0 ~, 1,
874 
875 #define UTIL_COMPL(b) UTIL_PRIMITIVE_CAT(UTIL_COMPL_, b)
876 #define UTIL_COMPL_0 1
877 #define UTIL_COMPL_1 0
878 
879 #define UTIL_BOOL(x) UTIL_COMPL(UTIL_NOT(x))
880 
881 #define UTIL_IIF(c) UTIL_PRIMITIVE_CAT(UTIL_IIF_, c)
882 #define UTIL_IIF_0(t, ...) __VA_ARGS__
883 #define UTIL_IIF_1(t, ...) t
884 
885 #define UTIL_IF(c) UTIL_IIF(UTIL_BOOL(c))
886 
887 /*
888  * These are like || and &&, but they do evaluation and
889  * short-circuiting at preprocessor time instead of runtime.
890  *
891  * UTIL_OR(foo, bar) is sometimes a replacement for (foo || bar)
892  * when "bar" is an expression that would cause a build
893  * error when "foo" is true.
894  *
895  * UTIL_AND(foo, bar) is sometimes a replacement for (foo && bar)
896  * when "bar" is an expression that would cause a build
897  * error when "foo" is false.
898  */
899 #define UTIL_OR(a, b) COND_CODE_1(UTIL_BOOL(a), (a), (b))
900 #define UTIL_AND(a, b) COND_CODE_1(UTIL_BOOL(a), (b), (0))
901 
902 #define UTIL_EAT(...)
903 #define UTIL_EXPAND(...) __VA_ARGS__
904 #define UTIL_WHEN(c) UTIL_IF(c)(UTIL_EXPAND, UTIL_EAT)
905 
906 #define UTIL_REPEAT(count, macro, ...)			    \
907 	UTIL_WHEN(count)				    \
908 	(						    \
909 		UTIL_OBSTRUCT(UTIL_REPEAT_INDIRECT) ()	    \
910 		(					    \
911 			UTIL_DEC(count), macro, __VA_ARGS__ \
912 		)					    \
913 		UTIL_OBSTRUCT(macro)			    \
914 		(					    \
915 			UTIL_DEC(count), __VA_ARGS__	    \
916 		)					    \
917 	)
918 #define UTIL_REPEAT_INDIRECT() UTIL_REPEAT
919 
920 /**
921  * @brief Generates a sequence of code.
922  *
923  * Useful for generating code like;
924  *
925  * NRF_PWM0, NRF_PWM1, NRF_PWM2,
926  *
927  * @arg LEN: The length of the sequence. Must be defined and less than
928  * 20.
929  *
930  * @arg F(i, ...): A macro function that accepts at least two arguments.
931  *  F is called repeatedly, the first argument is the index in the sequence,
932  *  the variable list of arguments passed to UTIL_LISTIFY are passed through
933  *  to F.
934  *
935  * Example:
936  *
937  *    \#define FOO(i, _) NRF_PWM ## i ,
938  *    { UTIL_LISTIFY(PWM_COUNT, FOO) }
939  *    The above two lines will generate the below:
940  *    { NRF_PWM0 , NRF_PWM1 , }
941  *
942  * @note Calling UTIL_LISTIFY with undefined arguments has undefined
943  * behavior.
944  */
945 #define UTIL_LISTIFY(LEN, F, ...) UTIL_EVAL(UTIL_REPEAT(LEN, F, __VA_ARGS__))
946 
947 /* Set of internal macros used for FOR_EACH series of macros. */
948 #define Z_FOR_EACH_IDX(count, n, macro, semicolon, fixed_arg0, fixed_arg1, ...)\
949 	UTIL_WHEN(count)						\
950 	(								\
951 		UTIL_OBSTRUCT(macro)					\
952 		(							\
953 			fixed_arg0, fixed_arg1, n, GET_ARG1(__VA_ARGS__)\
954 		)semicolon						\
955 		UTIL_OBSTRUCT(Z_FOR_EACH_IDX_INDIRECT) ()		\
956 		(							\
957 			UTIL_DEC(count), UTIL_INC(n), macro, semicolon, \
958 			fixed_arg0, fixed_arg1,				\
959 			GET_ARGS_LESS_1(__VA_ARGS__)			\
960 		)							\
961 	)
962 
963 #define Z_FOR_EACH_IDX_INDIRECT() Z_FOR_EACH_IDX
964 
965 #define Z_FOR_EACH_IDX2(count, iter, macro, sc, fixed_arg0, fixed_arg1, ...) \
966 	UTIL_EVAL(Z_FOR_EACH_IDX(count, iter, macro, sc,\
967 				 fixed_arg0, fixed_arg1, __VA_ARGS__))
968 
969 #define Z_FOR_EACH_SWALLOW_NOTHING(F, fixed_arg, index, arg) \
970 	F(index, arg, fixed_arg)
971 
972 #define Z_FOR_EACH_SWALLOW_FIXED_ARG(F, fixed_arg, index, arg) F(index, arg)
973 
974 #define Z_FOR_EACH_SWALLOW_INDEX_FIXED_ARG(F, fixed_arg, index, arg) F(arg)
975 #define Z_FOR_EACH_SWALLOW_INDEX(F, fixed_arg, index, arg) F(arg, fixed_arg)
976 
977 /**
978  * @brief Calls macro F for each provided argument with index as first argument
979  *	  and nth parameter as the second argument.
980  *
981  * Example:
982  *
983  *     #define F(idx, x) int a##idx = x;
984  *     FOR_EACH_IDX(F, 4, 5, 6)
985  *
986  * will result in following code:
987  *
988  *     int a0 = 4;
989  *     int a1 = 5;
990  *     int a2 = 6;
991  *
992  * @param F Macro takes index and first argument and nth variable argument as
993  *	    the second one.
994  * @param ... Variable list of argument. For each argument macro F is executed.
995  */
996 #define FOR_EACH_IDX(F, ...) \
997 	Z_FOR_EACH_IDX2(NUM_VA_ARGS_LESS_1(__VA_ARGS__, _), \
998 			0, Z_FOR_EACH_SWALLOW_FIXED_ARG, /*no ;*/, \
999 			F, 0, __VA_ARGS__)
1000 
1001 /**
1002  * @brief Calls macro F for each provided argument with index as first argument
1003  *	  and nth parameter as the second argument and fixed argument as the
1004  *	  third one.
1005  *
1006  * Example:
1007  *
1008  *     #define F(idx, x, fixed_arg) int fixed_arg##idx = x;
1009  *     FOR_EACH_IDX_FIXED_ARG(F, a, 4, 5, 6)
1010  *
1011  * will result in following code:
1012  *
1013  *     int a0 = 4;
1014  *     int a1 = 5;
1015  *     int a2 = 6;
1016  *
1017  * @param F Macro takes index and first argument and nth variable argument as
1018  *	    the second one and fixed argumnet as the third.
1019  * @param fixed_arg Fixed argument passed to F macro.
1020  * @param ... Variable list of argument. For each argument macro F is executed.
1021  */
1022 #define FOR_EACH_IDX_FIXED_ARG(F, fixed_arg, ...) \
1023 	Z_FOR_EACH_IDX2(NUM_VA_ARGS_LESS_1(__VA_ARGS__, _), \
1024 			0, Z_FOR_EACH_SWALLOW_NOTHING, /*no ;*/, \
1025 			F, fixed_arg, __VA_ARGS__)
1026 
1027 /**
1028  * @brief Calls macro F for each provided argument.
1029  *
1030  * Example:
1031  *
1032  *     #define F(x) int a##x;
1033  *     FOR_EACH(F, 4, 5, 6)
1034  *
1035  * will result in following code:
1036  *
1037  *     int a4;
1038  *     int a5;
1039  *     int a6;
1040  *
1041  * @param F Macro takes nth variable argument as the argument.
1042  * @param ... Variable list of argument. For each argument macro F is executed.
1043  */
1044 #define FOR_EACH(F, ...) \
1045 	Z_FOR_EACH_IDX2(NUM_VA_ARGS_LESS_1(__VA_ARGS__, _), \
1046 			0, Z_FOR_EACH_SWALLOW_INDEX_FIXED_ARG, /*no ;*/, \
1047 			F, 0, __VA_ARGS__)
1048 
1049 /**
1050  * @brief Calls macro F for each provided argument with additional fixed
1051  *	  argument.
1052  *
1053  * After each iteration semicolon is added.
1054  *
1055  * Example:
1056  *
1057  *     static void func(int val, void *dev);
1058  *     FOR_EACH_FIXED_ARG(func, dev, 4, 5, 6)
1059  *
1060  * will result in following code:
1061  *
1062  *     func(4, dev);
1063  *     func(5, dev);
1064  *     func(6, dev);
1065  *
1066  * @param F Macro takes nth variable argument as the first parameter and
1067  *	     fixed argument as the second parameter.
1068  * @param fixed_arg Fixed argument forward to macro execution for each argument.
1069  * @param ... Variable list of argument. For each argument macro F is executed.
1070  */
1071 #define FOR_EACH_FIXED_ARG(F, fixed_arg, ...) \
1072 	Z_FOR_EACH_IDX2(NUM_VA_ARGS_LESS_1(__VA_ARGS__, _), \
1073 			0, Z_FOR_EACH_SWALLOW_INDEX, ;, \
1074 			F, fixed_arg, __VA_ARGS__)
1075 
1076 /**@brief Implementation details for NUM_VAR_ARGS */
1077 #define NUM_VA_ARGS_LESS_1_IMPL(				\
1078 	_ignored,						\
1079 	_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10,		\
1080 	_11, _12, _13, _14, _15, _16, _17, _18, _19, _20,	\
1081 	_21, _22, _23, _24, _25, _26, _27, _28, _29, _30,	\
1082 	_31, _32, _33, _34, _35, _36, _37, _38, _39, _40,	\
1083 	_41, _42, _43, _44, _45, _46, _47, _48, _49, _50,	\
1084 	_51, _52, _53, _54, _55, _56, _57, _58, _59, _60,	\
1085 	_61, _62, N, ...) N
1086 
1087 /**
1088  * @brief Macro to get the number of arguments in a call variadic macro call.
1089  * First argument is not counted.
1090  *
1091  * param[in]    ...     List of arguments
1092  *
1093  * @retval  Number of variadic arguments in the argument list
1094  */
1095 #define NUM_VA_ARGS_LESS_1(...) \
1096 	NUM_VA_ARGS_LESS_1_IMPL(__VA_ARGS__, 63, 62, 61, \
1097 	60, 59, 58, 57, 56, 55, 54, 53, 52, 51,		 \
1098 	50, 49, 48, 47, 46, 45, 44, 43, 42, 41,		 \
1099 	40, 39, 38, 37, 36, 35, 34, 33, 32, 31,		 \
1100 	30, 29, 28, 27, 26, 25, 24, 23, 22, 21,		 \
1101 	20, 19, 18, 17, 16, 15, 14, 13, 12, 11,		 \
1102 	10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, ~)
1103 
1104 /**
1105  * Macro that process all arguments using given macro
1106  *
1107  * @deprecated Use FOR_EACH instead.
1108  *
1109  * @param ... Macro name to be used for argument processing followed by
1110  *            arguments to process. Macro should have following
1111  *            form: MACRO(argument).
1112  *
1113  * @return All arguments processed by given macro
1114  */
1115 #define MACRO_MAP(...) __DEPRECATED_MACRO FOR_EACH(__VA_ARGS__)
1116 
1117 /**
1118  * @brief Mapping macro that pastes results together
1119  *
1120  * Like @ref MACRO_MAP(), but pastes the results together into a
1121  * single token by repeated application of @ref UTIL_CAT().
1122  *
1123  * For example, with this macro FOO:
1124  *
1125  *     #define FOO(x) item_##x##_
1126  *
1127  * MACRO_MAP_CAT(FOO, a, b, c) expands to the token:
1128  *
1129  *     item_a_item_b_item_c_
1130  *
1131  * @param ... Macro to expand on each argument, followed by its
1132  *            arguments. (The macro should take exactly one argument.)
1133  * @return The results of expanding the macro on each argument, all pasted
1134  *         together
1135  */
1136 #define MACRO_MAP_CAT(...) MACRO_MAP_CAT_(__VA_ARGS__)
1137 #define MACRO_MAP_CAT_(...)						\
1138 	/* To make sure it works also for 2 arguments in total */	\
1139 	MACRO_MAP_CAT_N(NUM_VA_ARGS_LESS_1(__VA_ARGS__), __VA_ARGS__)
1140 
1141 /**
1142  * @brief Mapping macro that pastes a fixed number of results together
1143  *
1144  * Similar to @ref MACRO_MAP_CAT(), but expects a fixed number of
1145  * arguments. If more arguments are given than are expected, the rest
1146  * are ignored.
1147  *
1148  * @param N   Number of arguments to map
1149  * @param ... Macro to expand on each argument, followed by its
1150  *            arguments. (The macro should take exactly one argument.)
1151  * @return The results of expanding the macro on each argument, all pasted
1152  *         together
1153  */
1154 #define MACRO_MAP_CAT_N(N, ...) MACRO_MAP_CAT_N_(N, __VA_ARGS__)
1155 #define MACRO_MAP_CAT_N_(N, ...) UTIL_CAT(MACRO_MC_, N)(__VA_ARGS__,)
1156 
1157 #define MACRO_MC_0(...)
1158 #define MACRO_MC_1(m, a, ...)  m(a)
1159 #define MACRO_MC_2(m, a, ...)  UTIL_CAT(m(a), MACRO_MC_1(m, __VA_ARGS__,))
1160 #define MACRO_MC_3(m, a, ...)  UTIL_CAT(m(a), MACRO_MC_2(m, __VA_ARGS__,))
1161 #define MACRO_MC_4(m, a, ...)  UTIL_CAT(m(a), MACRO_MC_3(m, __VA_ARGS__,))
1162 #define MACRO_MC_5(m, a, ...)  UTIL_CAT(m(a), MACRO_MC_4(m, __VA_ARGS__,))
1163 #define MACRO_MC_6(m, a, ...)  UTIL_CAT(m(a), MACRO_MC_5(m, __VA_ARGS__,))
1164 #define MACRO_MC_7(m, a, ...)  UTIL_CAT(m(a), MACRO_MC_6(m, __VA_ARGS__,))
1165 #define MACRO_MC_8(m, a, ...)  UTIL_CAT(m(a), MACRO_MC_7(m, __VA_ARGS__,))
1166 #define MACRO_MC_9(m, a, ...)  UTIL_CAT(m(a), MACRO_MC_8(m, __VA_ARGS__,))
1167 #define MACRO_MC_10(m, a, ...) UTIL_CAT(m(a), MACRO_MC_9(m, __VA_ARGS__,))
1168 #define MACRO_MC_11(m, a, ...) UTIL_CAT(m(a), MACRO_MC_10(m, __VA_ARGS__,))
1169 #define MACRO_MC_12(m, a, ...) UTIL_CAT(m(a), MACRO_MC_11(m, __VA_ARGS__,))
1170 #define MACRO_MC_13(m, a, ...) UTIL_CAT(m(a), MACRO_MC_12(m, __VA_ARGS__,))
1171 #define MACRO_MC_14(m, a, ...) UTIL_CAT(m(a), MACRO_MC_13(m, __VA_ARGS__,))
1172 #define MACRO_MC_15(m, a, ...) UTIL_CAT(m(a), MACRO_MC_14(m, __VA_ARGS__,))
1173 
1174 #ifdef __cplusplus
1175 }
1176 #endif
1177 
1178 #endif /* _UTIL__H_ */
1179