Can someone explain me this syntax? It comes from the Hi Tech C include file
/* STATUS bits */
static volatile bit IRP @ (unsigned)&STATUS*8+7;
static volatile bit RP1 @ (unsigned)&STATUS*8+6;
static volatile bit RP0 @ (unsigned)&STATUS*8+5;
static volatile bit TO @ (unsigned)&STATUS*8+4;
static volatile bit PD @ (unsigned)&STATUS*8+3;
static volatile bit ZERO @ (unsigned)&STATUS*8+2;
static volatile bit DC @ (unsigned)&STATUS*8+1;
static volatile bit CARRY @ (unsigned)&STATUS*8+0;
I presume these are peripherail hardware registers. The bit
type and @
are non-standard. @
places them at absolute addresses given by STATUS
. bit
tells the compiler that the addresses are actually single bits, so it possibly has to use appropriate instructions (bit-operations).
According to @LPs' comment (and after some thought), this looks like PIC-MCU (you did not state the CPU used). The bit
type tells the compiler the addresses of the objects (ZERO
, etc.) address single bits in the "RAM" (STATUS
is actually a CPU register memory-mapped) address space. The bit-number is packed into the lower 3 bits (bit 0..7) and the byte-address is in the upper bits.
The right side of the @
calculats this bit-address: (8 bits/byte, hence the multiplication) and bit-number (lower 3 bits, hence the addition. Alternatively one could use bit-operators (identical result):
static volatile bit IRP @ ((unsigned)&STATUS << 3) | 7;
...
I'm very sure, @
and bit
are explained in the compiler documentation.
Note that the bit-type is actually violating the C standard, as this mandates the smallest addressable type to be char
with at least 8 bits and sizeof(char) == 1
.