Table of Contents Previous topic Next topic
C COMPILER->8051 Specific Features->Bit Objects
The bit data type is declared with the _bit keyword. For instance:
Variable flag will be 1 bit wide and will be located in the 8051's bit addressable memory area. flag can contain the value 0 or 1.
A bit variable can also be declared as a bit offset into an object that has been located in bit addressable memory. See the section Bit Addressable Objects for more information.
Bit data types can produce very efficient code. For instance the code:
results in a simple jb _flag,<label> instruction.
If a bit object is used in an arithmetic expression, it's value will be converted to unsigned char prior to the evaluation of the expression.
The bit data type can always be used for global variables. It can also be used for local variables and function arguments providing the function is a non-reentrant type and the function is never called by a function pointer. The linker will also overlay them if possible. If the function is reentrant the _bit keyword can still be used. However any local variables or function arguments declared with the _bit keyword will be quietly converted to unsigned char.
A pointer to a bit cannot be declared and the '&' operator cannot be used to take the address of a bit object.