我似乎无法将参数传递给需要不同参数的函数(或传递给实现第一个类型的子集的其他 _Generic 宏)。
#define DEBUG_PRINT(x,...) _Generic((x), \
debug_print_options *: DEBUG_PRINT_CUSTOM_TYPE(x, __VA_ARGS__), \
default: DEBUG_PRINT_BASIC_TYPE(x, __VA_ARGS__))
#define DEBUG_PRINT_BASIC_TYPE(x,...) debug_print_printf_specifier((#x), (x), TYPE_TO_PRINTF_SPECIFIER(x), __FILE__, __LINE__, _my_func__, &((struct debug_print_options){__VA_ARGS__}))
#define DEBUG_PRINT_CUSTOM_TYPE(x,...) debug_print_custom_to_debug_string((#x), (x), GET_CREATE_DEBUG_STRING_FUNC(x), __FILE__, __LINE__, _my_func__, &((struct debug_print_options){__VA_ARGS__}))
给出编译错误:
debug_print.h:123:46: error: ‘_Generic’ selector of type ‘struct debug_print_options *’ is not compatible with any association
这使得它看起来像是在每个分支机构都得到了评估。如果我注释掉它会编译的默认值。
有办法解决这个问题吗?