fix(system): rename __VA_NARG__ macro

__VA_NARG__ is copied from a forum post and is a pretty common implementation
with a high chance of causing naming collision

Added ESP_ namespace to avoid this.
This commit is contained in:
Marius Vikhammer
2024-10-10 11:10:51 +08:00
parent 6846245815
commit 64e0fc7a5a
7 changed files with 43 additions and 28 deletions

View File

@@ -1,4 +1,4 @@
idf_component_register(SRCS "test_app_main.c" "test_attr.c"
idf_component_register(SRCS "test_app_main.c" "test_attr.c" "test_esp_macro.c"
INCLUDE_DIRS "."
PRIV_REQUIRES unity esp_mm esp_psram
WHOLE_ARCHIVE)

View File

@@ -0,0 +1,21 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
#include "esp_macros.h"
/* test macros */
#define foo_args(...) 1
#define foo_no_args() 2
#if defined(__cplusplus) && (__cplusplus > 201703L)
#define foo(...) CHOOSE_MACRO_VA_ARG(foo_args, foo_no_args __VA_OPT__(,) __VA_ARGS__)(__VA_ARGS__)
#else
#define foo(...) CHOOSE_MACRO_VA_ARG(foo_args, foo_no_args, ##__VA_ARGS__)(__VA_ARGS__)
#endif
ESP_STATIC_ASSERT(foo() == 2, "CHOOSE_MACRO_VA_ARG() result does not match for 0 arguments");
ESP_STATIC_ASSERT(foo(42) == 1, "CHOOSE_MACRO_VA_ARG() result does not match for 1 argument");
#if defined(__cplusplus) && (__cplusplus > 201703L)
ESP_STATIC_ASSERT(foo(42, 87) == 1, "CHOOSE_MACRO_VA_ARG() result does not match for n arguments");
#endif