args.h 1.0 KB

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