I was reading Stroustrup's c++ FAQ and I noticed that, at one point, he had a writeonly qualifier in the language. After some discussion, a colleague and I could only come up with one purpose - side effects, specifically in the case of some me开发者_运维问答mory mapped IO. Is there any other legitimate usage for a writeonly qualifier?
The write-only
qualifier would be useful for hardware registers since reading from a write-only
register would lead to undefined behavior or subtle run-time errors. You can use a #define
such as #define write-only
and then apply this to a register like, special_register write_only UTXBUF;
There is a blog post at EE Times on How to Enforce write-only access.
It's made a comeback in C++ AMP, GPGPU extensions to the language, where it's used to tell the run-time that they don't have to copy certain buffers from host to device.
It is useful for many type of hardware interfaces which do not allow reading the computer's output, or in which the input is status and the output is control, etc.
In my device driver writing days, this occurred pretty frequently among hardware designs. 1970s hardware was relatively expensive to add a buffer which could read back that which was last written to it, or there was a cost-saving interface at the same address as the output register which returned something else about the device. When and where it mattered, the driver had to maintain a copy of the last value written to consult if, for example, an update would actually cause a change in state.
精彩评论