What is called the above technique?
Bit fields. And you should use int ( signed , unsigned or otherwise) as a "type", not a char .
Is the class four bytes in size or one byte in size?
None. This is probably sizeof(int) , because the compiler creates a word-size object. However, the actual bit fields will be stored in bytes. It just wastes some space.
Are variables processed as 1 (or 3) bits as shown, or as an "unsigned char", processed like every byte?
They represent only the indicated bits and will be packed as tightly as possible.
Is there a way to combine bits with a centralized byte? For example:
Use union :
struct bits { unsigned A:1; unsigned B:3; unsigned C:1; unsigned D:3; }; union SplitByte { struct bits Bits; unsigned char Byte[sizeof(struct bits)]; } SplitByteObj;
Please note that there are problems with bit fields, for example, when using streams. Each bit field cannot be obtained individually, so you can get errors if you try to use the mutex to protect each of them. In addition, the order in which the fields are laid out is not clearly defined by the standard. For this reason, many people prefer to use bitwise operators to implement bit fields manually.
Is there an article that covers this topic in more detail?
Little. The first few you get when Google is all you find. They are not a commonly used design. Itβs best to bite off the standard to determine exactly how they work so that you donβt bite a strange edge. I could not say exactly where in the standard they are indicated.
If "A: 1" is treated as a complete byte, what is its dot / purple?
This is not so, but I have already turned to it.