xref: /linux-6.15/include/linux/args.h (revision d51e783c)
1b229baa3SAndy Shevchenko /* SPDX-License-Identifier: GPL-2.0 */
2b229baa3SAndy Shevchenko 
3b229baa3SAndy Shevchenko #ifndef _LINUX_ARGS_H
4b229baa3SAndy Shevchenko #define _LINUX_ARGS_H
5b229baa3SAndy Shevchenko 
6b229baa3SAndy Shevchenko /*
7b229baa3SAndy Shevchenko  * How do these macros work?
8b229baa3SAndy Shevchenko  *
9b229baa3SAndy Shevchenko  * In __COUNT_ARGS() _0 to _12 are just placeholders from the start
10b229baa3SAndy Shevchenko  * in order to make sure _n is positioned over the correct number
11b229baa3SAndy Shevchenko  * from 12 to 0 (depending on X, which is a variadic argument list).
12b229baa3SAndy Shevchenko  * They serve no purpose other than occupying a position. Since each
13b229baa3SAndy Shevchenko  * macro parameter must have a distinct identifier, those identifiers
14b229baa3SAndy Shevchenko  * are as good as any.
15b229baa3SAndy Shevchenko  *
16b229baa3SAndy Shevchenko  * In COUNT_ARGS() we use actual integers, so __COUNT_ARGS() returns
17b229baa3SAndy Shevchenko  * that as _n.
18b229baa3SAndy Shevchenko  */
19b229baa3SAndy Shevchenko 
20*d51e783cSKP Singh /* This counts to 15. Any more, it will return 16th argument. */
21*d51e783cSKP Singh #define __COUNT_ARGS(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _n, X...) _n
22*d51e783cSKP Singh #define COUNT_ARGS(X...) __COUNT_ARGS(, ##X, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)
23b229baa3SAndy Shevchenko 
24b229baa3SAndy Shevchenko /* Concatenate two parameters, but allow them to be expanded beforehand. */
25b229baa3SAndy Shevchenko #define __CONCAT(a, b) a ## b
26b229baa3SAndy Shevchenko #define CONCATENATE(a, b) __CONCAT(a, b)
27b229baa3SAndy Shevchenko 
28b229baa3SAndy Shevchenko #endif	/* _LINUX_ARGS_H */
29