I'm trying to squeeze as much out of my memory as possible.
I have a matrix of 4.9999995e13
ints but they only need to be true or false - basically I only need one bit of storage for each of these ints.
I understand that there are no single bit types in C (maybe someone can explain why, to me), and I also know that if a short short int
existed it would be 1 byte, same as char. However all of the logical operations in C return ints (as well as a few other functions).
So my questions are:
short short int
exist?char
instead, would I have performance decrease because of all the casting to int
that would have to be done?Just in-case it's relevant, I am compiling with GCC for C99.
EDIT I've just seen on this wikipedia page that there is a _Bool
type, is this actually standard?
The _Bool
type is standard in the most recent version of C, but that's still not what you want, because a _Bool
still takes up at least one byte (as does a char
, by definition).
No, if you want that many boolean bits you need to pack them into a bitfield or bit array. There is no standard datatype for bitfields in C, so you're also going to have to write your own macros or functions for getting the bit at a particular offset. I also hope that you're going to run this on a 64-bit machine with plenty of RAM, otherwise you're going to run out of memory and fast.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With