I have had, in the last few months, a legitimate use for const, albeit in C++, not C. I've had to simulate, in software, a paging memory system and it's translation look-aside buffer. One of the big optimizations is to know if the data in the page is dirty or not, avoiding writing it back. To make our regular code run on this annoying little processor, we chose to replace some STL-like implementations with versions that indirect (and manage) our TLB. The catch now is to know if you are accessing the data as an L-value or R-value, and const overloading can do that for you. Ugly.

Here's a related question: There are read-only (const) variables, and read-write variables. Is there any way to notate a write-only variable in C? I'd like to be able to denote that something is a stream (represented in an array) I can write to, but never read from, which would let me better control the behaviour of flushing that data back out of a local store.

Paul

On 7-Dec-05, at 7:05 AM, Steve Simon wrote:

My understanding is that const was depricated for the same reason that
register is - the compiler is in a much better position to judge what
data is constant than the programmer.

The one place where it would have been very useful (to me) was
writing ROMable embedded code, but these days with 32bit embedded
CPUs I don't have physicially readonly data.

To cap this the last time I did use a 16bit cpu and tried to do this,
examination of the assembly proved the (name deleted) compiler was too
dumb to take advantage.

-Steve

Reply via email to