1 2 3 4 5 | int64 value = UINT32_MAX + 1; bool32 asBool = value; if (asBool) { // WIll not enter if, asBool == 0! } |
cmuratori
I like to make sure that I know the sizes of everything that I put in my structures.
cmuratori
Performance is usually pretty far down the line of reasons as to why I don't like plain "bool". I suspect that the performance isn't particularly relevant most of the time, at least not nowadays.
Nimbalcmuratori
I like to make sure that I know the sizes of everything that I put in my structures.
Could you elaborate on the reason(s) for this?
cmuratori
One very important one is that it is not clear how big "bool" is, whereas it is very clear how big "bool32" is, and generally I like to make sure that I know the sizes of everything that I put in my structures.
C0D3
blah = VirtualAlloc(1000mb
so he can do
mystruct* one = (mystuct*) blah
and that chunk will store "one".
then he can do more
mystruct2* two = (mystruct2*) (sizeof(mystruct) + blah)
to store "two" in that chunk. This just adds the the size of mystruct to the address of blah to get a new offset in that chunk so we can store mystruct2.
The size of a structure is all of the variable sizes inside that structure. If you are not sure of a size of a variable then it would be hard to do this easy calculation.
1 2 3 4 5 6 | struct S { int x; bool y; int z; }; |
mmozeiko
If somebody missed, Casey talked about why he uses bool32 not bool in previous episodes:
https://forums.handmadehero.org/j...videos/win32-platform/day007.html "Bool datatype idiosyncraries (9:21)"
https://forums.handmadehero.org/j...videos/win32-platform/day009.html "Sometimes you use 'bool' and sometimes 'bool32' (1:48:48)"
As for knowing sizes I would assume it's more about alignment in structures or array of structures. If you do this:
1 2 3 4 5 6 struct S { int x; bool y; int z; };
and you are not paying attention to bool size, then it could be that sizeof(bool) is 1 and then sizeof(S) is 12, not 9. If you are not careful with this, you will be wasting a lot of space.
That's why you want to specify exact sizes, so you know what is happening. If you put bool32 in this struct, then you know exactly what is happening.
mmozeiko
If you are not careful with this, you will be wasting a lot of space.