I’ve been trying to learn C++ and one of the things I do is to read the C++ templates’ codes, where I found that you can use uint32 to declare a bool. Then I googled and found this: Using uint32:1 to Create a Boolean - UE4 AnswerHub and this: https://forums.unrealengine.com/showthread.php?49912-Why-does-UE4-use-uint32-to-represent-a-bool (I thought this would be a common C++ technique but the google results are all UE4 related…it seems like Epic Games‘ secret art…)
The reason for doing this is quite clear in those two posts. I still have some questions that I didn’t find answers to though.
Most importantly, how to use it… The MSDN link in the AnswerHub post has 2 examples, both of which are data structs. Naturally I would assume one has to declare a bunch of bools in a struct using uint32 to benefit from it. But in the template (twinstick shooter template to be exact) they just declared a lonely bool “bCanFire”.
Say I have an actor class where a bool is stored this way, and I have 32 instances of this actor placed in my level, are these 32 instances’ bool variables stored in a single uint32 or 32 different uint32s? What if I have 32 classes and each of them has a bool stored this way and one instance in the level?
Generally, if I keep all my bools in all classes declared this way, will I be saving memory? Or do I have to declare like more than 4 bools in a single struct to save memory?
Being declared this way, I assumed it’ll be used like this: if (bCanFire == 1), however in the code they just wrote if (bCanFire == true). Does this mean that those 1 bit bools can be used exactly the same as a normal 1 byte bool? If so, why not jut if (bCanFire)?
Sorry it might be too long for a rather simple question. Thanks for helping!