As the title, the declaration uint32 blabla:1 declares a variable of type uint32, and the size of the variable is 1 bit, right? If that so, then don’t we declare it as a bool?
Also, uint32 : 1, uint16 : 1, uint8 : 1 all have size 1 bit right?
The number after uint specifies the Size of the Integer
uint32 ist an unsigned integer with 32 Bit so it can hold values from 0 to 2^32
The same goes for uint16 (16 Bit) and uint8 (8 Bit)
A bools Size should be 8 Bit so 1 Byte, because it only uses 1 Bit, but to be “adressable” the size of a variable should be at least 8 Bit.
I heard that in some Compilers bool are 4 Byte long (32 Bit) but I don’t know if this is TRUE or FALSE (hehe)
I hope I could answer your question :))
You probably should declare it as a bool.
uint32:1 declares the variable as a bit field, a set of bits within a bigger integer type.
bool declares your variable as a tiny integer. There are subtle, compiler-dependent implications of a bit field, but these have a negligible impact on your performance. Bit fields don’t support pointers nor non-const references, which may or may not matter to you. Ultimately, the most important thing is to choose the version that is easiest to read.
Thanks! It’s clearer right now.
Thanks, dbuchoff! Are there any textbooks which I can delve into more? I only read c++ Primer plus 5th edition and there’s only a brief introduction.
C++ is a huge language, and frankly it’s not worth learning the whole thing just for Unreal development. I liked A Tour of C++. I also like Effective Modern C++, but wouldn’t recommend it, since you’re not going to be taking advantage of many language features (e.g. braced initializers, since in Unreal code, you never call the constructor directly; e.g. references, since most code is going to pass UObjects around by pointer). Also, most books are going to use standard C++ libraries (like std::vector), which should not be used when a more Unreal-ish alternative exists (like TArray).
I highly recommend only learning language features when you need them or see them in code you are working with.
Much thanks! I will take your advice seriously.