Write-only variables

Raphael Mankin raph at tigger.planet.bt.co.uk
Thu Sep 14 19:50:57 AEST 1989


How does one declare write-only variables in C? This is not as silly a
question as it sounds. I can declare read-only variables as 'const' or
'const volatile'; the latter corresponds to a read-only register in a
memory-mapped device. Now, 'const volatile' sounds like a contradiction
in terms, but that is how it is done.

If I have a write-only device register it would be a write-only
variable to C.

BTW some devices behave differently when one reads
them from when one writes them. Some UARTs, for instance, (6850 I
think) map the status register (read only) to the same location as a
control register (write only). One tells a compiler that the
value it just wrote to a location is ALWAYS different from the value it
will read back by the use of 'volatile'. 'Volatile' is not quite
strong enough here, but it is what we have.

Raphael Mankin
raph at planet.bt.co.uk
-- 
Raphael Mankin
raph at planet.bt.co.uk



More information about the Comp.lang.c mailing list