Skip to content

sys: util_macro: Support macros as arguments#97689

Merged
jhedberg merged 1 commit into
zephyrproject-rtos:mainfrom
raffi-g:util-macros
Oct 22, 2025
Merged

sys: util_macro: Support macros as arguments#97689
jhedberg merged 1 commit into
zephyrproject-rtos:mainfrom
raffi-g:util-macros

Conversation

@raffi-g
Copy link
Copy Markdown
Contributor

@raffi-g raffi-g commented Oct 16, 2025

I adjusted GET_ARG_N and GET_ARGS_LESS_N to use UTIL_CAT instead of simple concatenation. This allows to use a macro as the argument N instead of only literal numbers. So for example this would be possible now:

#define CONFIG_BAUDRATE_INDEX 3 /* from kconfig */
uint32_t baudrate = GET_ARG_N(CONFIG_BAUDRATE_INDEX, 9600, 19200, 38400, 57600);
/* baudrate == 38400 */

I also adjusted the unit tests to showcase this. (I can also revert this part, if it is not wished to have this in the tests.)

@zephyrbot zephyrbot added area: Tests Issues related to a particular existing or missing test area: Testsuite Testsuite area: Base OS Base OS Library (lib/os) labels Oct 16, 2025
Adjusted GET_ARG_N and GET_ARGS_LESS_N to use UTIL_CAT instead of simple
concatenation. This allows to use a macro as the argument N instead of
only numbers.

Adjusted the unit tests to showcase this.

Signed-off-by: Greter Raffael <rgreter@baumer.com>
@sonarqubecloud
Copy link
Copy Markdown

@jhedberg jhedberg merged commit a6eaa54 into zephyrproject-rtos:main Oct 22, 2025
26 checks passed
@raffi-g raffi-g deleted the util-macros branch October 27, 2025 16:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: Base OS Base OS Library (lib/os) area: Tests Issues related to a particular existing or missing test area: Testsuite Testsuite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants