mardi 23 février 2016

How many bits does an enum value need?

#include <stdint.h>

enum state : uint8_t {
    NONE,
    USA,
    CAN,
    MEX
};

struct X {
    state st : 2;  // compiles with uint8_t st : 2
};

Clang 3.9.0 compiles successfully.

GCC 4.8.4 and 5.3.0 complain with:

warning: ‘X::st’ is too small to hold all values of ‘enum state’

Who is right?

Aucun commentaire:

Enregistrer un commentaire