Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Reading through Odin (very neat overall!) I am a bit confused on the additional boolean types. "bool" seems to be your standard boolean but then there are b8, b16, b32, and b64. Bitfields seem to be their own thing still so are these just boolean types with a wider backing for something like a data format that stores them that way?


There are a few reasons as to why there are different sized booleans in Odin.

One is dealing with foreign code. A lot of old C code used their own boolean type before it was standardized. And many people defaulted to typedeffing `int`. A good example of this is Win32's `BOOL` which is `int` sized, which would be backed by `b32` in Odin.

Another reason is that file formats may use different width booleans to a single byte.

Another reason is that things that are closer to the register-width are faster than byte-wide operations. So `b32` or `b64` even though it takes more memory up can be faster to deal with than `bool`/`b8`.

As for `bit_set`s in Odin, they are backed by integers and a brilliant solution to the problem of flags. They usually become a lot of people's favourite (but small) feature because of their ease of use and clarify of what they express.


Thanks, appreciate the detailed answer!




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: