-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Open
Description
This declaration doesn't work with clang on OSX:
#define mi_stats_t_decl(name) mi_stats_t name = { 0 }; name.size = sizeof(mi_stats_t); name.version = MI_STAT_VERSION;
It yields this:
mimalloc-3.2.8/src/stats.c:485:3: error: missing field 'version' initializer [-Werror,-Wmissing-field-initializers]
485 | mi_stats_t_decl(stats);
| ^
mimalloc-3.2.8/include/mimalloc-stats.h:119:54: note: expanded from macro 'mi_stats_t_decl'
119 | #define mi_stats_t_decl(name) mi_stats_t name = { 0 }; name.size = sizeof(mi_stats_t); name.version = MI_STAT_VERSION;
Attempted workaround using C99 designated initializers, which is also compatible with C++20.
#define mi_stats_t_decl(name) \
mi_stats_t name = { .size = sizeof(mi_stats_t), .version = MI_STAT_VERSION };
However, testing various levels of clang alone, that's seemingly not a viable option; some levels are happy with it, others demand that the entire struct be initialized. Therefore, the following is the best I've come up with so far:
#define mi_stats_t_decl(name) \
mi_stats_t name; \
memset(&name, 0, sizeof(mi_stats_t)); \
name.size = sizeof(mi_stats_t); \
name.version = MI_STAT_VERSION;
Which I'd characterize as 'ick', but perhaps someone else will have a better idea.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels