steering-wheel/Core/Inc/util.h

18 lines
726 B
C
Raw Normal View History

2023-04-04 22:05:50 +02:00
#ifndef INC_UTIL_H
#define INC_UTIL_H
// This is wacky preprocessor magic that allows us to count the number of
// members of an enum. Unfortunately, it doesn't work with enum classes, so we
// have to use C-style enums.
2023-05-23 02:51:40 +02:00
// The preprocessor magic is so wacky we have to prevent GCC from failing with a
// -Werror=pedantic when compiling the simulator
#pragma GCC diagnostic ignored "-Wpedantic"
2023-04-04 22:05:50 +02:00
#define CountedEnum(NAME, TYPE, ...) \
typedef enum { __VA_ARGS__ } NAME; \
2023-05-23 02:51:40 +02:00
static const size_t NAME##_COUNT = \
sizeof(__extension__(int[]){__VA_ARGS__}) / sizeof(int);
2023-04-04 22:05:50 +02:00
#endif // INC_UTIL_H