Skip to content

Commit f98fd62

Browse files
ycsinfabiobaltieri
authored andcommitted
include: sys: util: add note and test for NUM_VA_ARGS_LESS_1
Notes that `NUM_VA_ARGS_LESS_1` support up to 64 arguments, and added test for it in `tests/lib/sys_util`. Signed-off-by: Yong Cong Sin <[email protected]>
1 parent ae2cb14 commit f98fd62

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

include/zephyr/sys/util_macro.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,8 @@ extern "C" {
623623
/**
624624
* @brief Number of arguments in the variable arguments list minus one.
625625
*
626+
* @note Supports up to 64 arguments.
627+
*
626628
* @param ... List of arguments
627629
* @return Number of variadic arguments in the argument list, minus one
628630
*/

tests/lib/sys_util/src/main.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,21 @@ ZTEST(sys_util, test_NUM_VA_ARGS)
5252
/* support up to 63 args */
5353
zassert_equal(63, NUM_VA_ARGS(LISTIFY(63, ~, (,))));
5454
}
55+
56+
/**
57+
* @brief Test NUM_VA_ARGS_LESS_1 works as expected with typical use cases
58+
*
59+
* @see NUM_VA_ARGS_LESS_1()
60+
*/
61+
62+
ZTEST(sys_util, test_NUM_VA_ARGS_LESS_1)
63+
{
64+
zassert_equal(0, NUM_VA_ARGS_LESS_1());
65+
zassert_equal(0, NUM_VA_ARGS_LESS_1(_1));
66+
zassert_equal(1, NUM_VA_ARGS_LESS_1(_1, _2));
67+
/* support up to 64 args */
68+
zassert_equal(63, NUM_VA_ARGS_LESS_1(LISTIFY(64, ~, (,))));
69+
}
5570
/**
5671
* @}
5772
*/

0 commit comments

Comments
 (0)