Код: Выделить всё
#include
struct Register {
uint8_t field : 1;
};
int main() {
uint8_t byte{0}; // Read from a device
Register r;
r.field = (byte >> 5) & 0x1; // access bit 5
r.field = (byte >> 7) & 0x1; // access bit 7, warns
}
Любой идеи, почему это может быть? Или как это исправить, чтобы не предупреждать об ошибке преобразования?
Пример здесь, https://godbolt.org/z/Ghd5ndnKd
Подробнее здесь: https://stackoverflow.com/questions/787 ... -bit-field
Мобильная версия