assert sizes of smaller-than-int bit fields in structures
This commit is contained in:
parent
b3155a8bcb
commit
608c724add
|
@ -45,6 +45,10 @@ typedef unsigned long ulong;
|
|||
|
||||
#define BIT_ENUM(...)
|
||||
|
||||
#define static_assert_bits(pfx, type, field) \
|
||||
static_assert( pfx##__NUM_BITS <= sizeof(((type){ 0 }).field) * 8, \
|
||||
stringify(type) "::" stringify(field) " is too small" )
|
||||
|
||||
#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
|
||||
# define ATTR_UNUSED __attribute__((unused))
|
||||
# define ATTR_NORETURN __attribute__((noreturn))
|
||||
|
|
|
@ -74,6 +74,9 @@ typedef struct message {
|
|||
MESSAGE(struct message)
|
||||
} message_t;
|
||||
|
||||
static_assert_bits(F, message_t, flags);
|
||||
static_assert_bits(M, message_t, status);
|
||||
|
||||
// For driver_t->prepare_load_box(), which may amend the passed flags.
|
||||
// The drivers don't use the first two, but may set them if loading the
|
||||
// particular range is required to handle some other flag; note that these
|
||||
|
@ -108,6 +111,8 @@ typedef struct {
|
|||
uchar flags;
|
||||
} msg_data_t;
|
||||
|
||||
static_assert_bits(F, msg_data_t, flags);
|
||||
|
||||
#define DRV_OK 0
|
||||
/* Message went missing, or mailbox is full, etc. */
|
||||
#define DRV_MSG_BAD 1
|
||||
|
|
|
@ -36,6 +36,9 @@ typedef struct sync_rec {
|
|||
char tuid[TUIDL];
|
||||
} sync_rec_t;
|
||||
|
||||
static_assert_bits(F, sync_rec_t, flags);
|
||||
static_assert_bits(S, sync_rec_t, status);
|
||||
|
||||
typedef struct {
|
||||
int t[2];
|
||||
void (*cb)( int sts, void *aux ), *aux;
|
||||
|
|
Loading…
Reference in New Issue
Block a user