As far as I could find, the width of the bool
type is implementation-defined. But are there any fixed-width boolean types, or should I stick to, for e.g., a uint8_t
to represent a fixed-width bool?
[EDIT] I made this python script that auto-generates a C++ class which can hold the variables I want to be able to send between a micro controller and my computer. The way it works is that it also keeps two arrays holding a pointer to each one of these variables and the sizeof each one of them. This gives me the necessary information to easily serialize and deserialize each one of these variables. For this to work however the sizeof, endianness, etc of the variable types have to be the same on both sides since I'm using the same generated code on both sides. I don't know if this will be a problem yet, but I don't expect it to be. I have already worked with this (32bit ARM) chip before and haven't had problems sending integer and float types in the past. However it will be a few days until I'm back and can try booleans out on the chip. This might be a bigger issue later, since this code might be reused on other chips later.
So my question is. Is there a fixed width bool
type defined in the standard libraries or should I just use a uint8_t to represent the boolean?
bool
type is fixed attrue
andfalse
. How can 2 states have varying width? – Stereochemistrybool
? – Stereochemistrybool
will be 16-bits. Some microcontrollers can access a bit as the minimum size. – Stereochemistrybool
is 8 bits, with all but the low-order bit being set to 0. – Exarchbool
? ("Having a fixed width" is not an answer.) – Exarchx & FLAG
needs to become!!(x & FLAG)
– Amin