doc-helmut wrote:bit is not a C data type, not even bool, so having "bit" would make NXC even more unlike C.
Instead of NXC it would be then more like QUC (quite unlike C). I don't like this idea very much.
I don't see the issue, one of the fundamental ideas behind C++ is that you can create your own data types to extend the language.
Anyway, this would not be a change of the C language, it would be an extension and pretty much every C compiler (like gcc) extends C in a variety of ways.
But a bit variable type do correspond to a bool, as it must only as it must only contain the values true and false. I'm not sure if the spec enforces it, but it you compile this code with g++ you get 1:
Code: Select all
int i = (bool)457;
printf( "%d", i );
I also believe that there is no strict definition on how it must be implemented, so I don't think there would be anything wrong with saving it as one bit. (vector<bool> actually does this.)
Instead of using a byte for each bool, you could combine up to 8 separate bools into one byte. This is not thread safe however, so you would need to make the compiler smart enough to detect which variables are only used in the same thread. Quite a bit of work, but not impossible. Worth the effort? I wouldn't say so...
Again, I think bit fields would be more useful.