I read somewhere that using BOOL (typedef int) is better than using the standard c++ type bool because the size of BOOL is 4 bytes (i.e. a multiple of 4) and it saves alignment operations of variables into registers or something along those lines…
Is there any truth to this? I imagine that the compiler would pad the stack frames in order to keep alignments of multiple of 4s even if you use bool (1 byte)?
I’m by no means an expert on the underlying workings of alignments, registers, etc so I apologize in advance if I’ve got this completely wrong. I hope to be corrected. 🙂
Cheers!
First of all,
sizeof(bool)is not necessarily1. It is implementation-defined, giving the compiler writer freedom to choose a size that’s suitable for the target platform.Also,
sizeof(int)is not necessarily4.There are multiple issues that could affect performance:
What — if any — difference that makes to a particular piece of code can only be established by profiling that piece of code.