jeudi 21 septembre 2017

Does setting a 1-bit wide bitfield to 2 mean the bitfield is set or unset?

So I have a bitfield like so:

unsigned int foobar:1;

And then I set it using this code

uint32_t code = loadCode();
structure.foobar = code & 2;

So, if code is set to 2, would this mean that foobar is set to 1, 0, or undefined? The exact standard I'm using is actually C++11, not plain C.

Aucun commentaire:

Enregistrer un commentaire