Mail Archives: djgpp/1998/07/31/10:00:29
Destination: "Böhme Uwe" <uwe AT hof DOT baynet DOT de>
From: Gruber Gerhard
Group: comp.os.msdos.djgpp
Date: Fri, 31 Jul 1998 05:40:04 +0200:
>> I wonder how big a short int is (in bits) and if there are anything smaller
>> then an unsigned char (1, 2, 4 bits). I also wonder if there is any command
>> to read and write a single bit in a variable.
>>
>> Thanks in advance.
>
> I don't know weather there are packed bit arrays in ANSI.
>But one thing is clear. Even if there are, in most cases it's not very usefull
>(with very rare exception)' cause for the iXX processor there is no way to set
>a single bit despites the regular way with and(&) and or (|) and so you can do
>in C also.
>The sizeof operator will allways give you the size of the variable you are
>using.
>The n'th bit you get by (1<<n);
>You can set it by var|=(1<<n);
>You can wipe it by var&=~(1<<n);
>
>So why messing around with bitwise variables.
Because you have the advantage that in a debugging session you can print the
value of the variable. Using your method, you have to print the value and
calculate it by yourself. Also, if you program hardware registers, you can map
the bitfields to the register in youse and can adress it quite easy with a
variable name.
It has advantages.
--
Bye,
Gerhard
email: sparhawk AT eunet DOT at
g DOT gruber AT sis DOT co DOT at
Spelling corrections are appreciated.
- Raw text -