inline bool GetBit(unsigned short BitNum);
inline void SetBit(bool Bit, unsigned short BitNum);
};
When I set any bit in c++ main() function in the manner:
bool BIT=true;
TEightBits EB[3];
EB[1].bit1=BIT;
It works as I expected. But if I use function:
inline void SetBit(bool Bit, unsigned short BitNum)
{
switch (BitNum)
{
case 0: bit0=Bit;
case 1: bit1=Bit;
case 2: bit2=Bit;
case 3: bit3=Bit;
case 4: bit4=Bit;
case 5: bit5=Bit;
case 6: bit6=Bit;
case 7: bit7=Bit;
}
}
then all entries of a byte are set to true.
For example:
OMG!
What a embarassing mistake :[
Thank You very much. Lately I am programming in scilab and i just forgot that in c/c++ there has to be break in switch expr.
I'm just playing to learn some new things. That's all.
Thanks again :]
Have you thought about using the shift operator istead of using an bool-value for a single bit which is a waste of memory?
He's using bitfields which are already tightly packed, but automatically by the compiler instead of manually. Look at the definition of his class members in his original post.