enum: Allow specifying the name used when none of the flags are set

This commit is contained in:
Tobias Brunner
2022-04-14 18:42:01 +02:00
parent a5430e1601
commit 927103ece4
4 changed files with 14 additions and 11 deletions
+3 -2
View File
@@ -130,13 +130,14 @@ struct enum_name_t {
* @param name name of the enum_name list
* @param first enum value of the first enum string
* @param last enum value of the last enum string
* @param unset name used if no flags are set
* @param ... a list of strings
*/
#define ENUM_FLAGS(name, first, last, ...) \
#define ENUM_FLAGS(name, first, last, unset, ...) \
static enum_name_t name##last = {first, last + \
BUILD_ASSERT((__builtin_ffs(last)-__builtin_ffs(first)+1) == \
countof(((char*[]){__VA_ARGS__}))), \
ENUM_FLAG_MAGIC, { __VA_ARGS__ }}; ENUM_END(name, last)
ENUM_FLAG_MAGIC, { unset, __VA_ARGS__ }}; ENUM_END(name, last)
/**
* Convert a enum value to its string representation.