Possible Duplicate:
What does 'unsigned temp:3' means
I encountered a problem when I’m reading the code of Clang.
class LangOptions {
public:
unsigned Trigraphs : 1; // Trigraphs in source files.
unsigned BCPLComment : 1; // BCPL-style '//' comments.
...
};
This is the first time I saw the syntax ” : 1″, what’s the ” : 1″ stands for? Thanks!
It’s a bitfield, which means that the value will only use one bit, instead of 32 (or whatever
sizeof(unsigned) * <bits-per-byte>is on your platform).Bitfields are useful for writing compact binary data structures, although they come with some performance cost as the compiler/CPU cannot update a single bit, but needs to perform AND/OR operations when reading/writing a full byte.