Handmade Hero»Forums»Code
8 posts
Casey's criteria on types
Edited by Marchin on Reason: Initial post
So i'm following the series while coding along side with it (just finished episode 015) and one thing i still don't get is Casey's criteria when choosing between a specific int (int8, int16, etc) vs using regular int. Also i don't get why he uses bool32 instead of bool8. If someone could enlighten me about this i would be very grateful.
Mārtiņš Možeiko
2198 posts / 1 project
Casey's criteria on types
Later in series he uses int less and less. So mostly Casey uses only sized int types.

As for bool32 vs bool8 - operations with 32-bit number are more often more efficient. And when storing them inside struct then bool8 type could lead to useless 3 byte padding afterwards (if next member is >=32-bit type). Thus there's really no reason to use bool8. Only advantage is if you are storing million of them in array - but then you should use u8 or similar type for specialized code.
Miles
123 posts / 4 projects
Casey's criteria on types
Edited by Miles on
My advice is to familiarize yourself with the C struct padding/alignment rules. They're easy to understand and simple to apply, and they're your ticket to knowing when a smaller data type will save space in a struct vs. when it won't.

As for bool8 vs. plain bool, I think Casey's reasoning is that boolean overdetermination (which applies to the bool type, but not to integer types) can lead the compiler to generate slightly inefficient code.