On 13/10/2017 07:16, Gregory Ewing wrote:
Steve D'Aprano wrote:
On Fri, 13 Oct 2017 03:37 pm, Gregory Ewing wrote:

If the compiler can tell where p is initially pointing, it could
put the pointer in read-only memory.

If it's read-only, how can the compiler write to it?

(I come from the days when ROM was actual ROM, burned in at the factory.)

So, the factory is allowed to write to it. Possibly
it's writing data that came from... a compiler?

A memory that couldn't be written to at all, ever, would
be a bit useless!


It's read-only in the same sense as a printed book; you can't change the marks already on the page.

I've programmed EPROMS. Neither the C language nor the concept of 'const' attributes for data ever came into it. While executable code doesn't really need it.

It is simply not a necessity. You just arranged for writeable portions of memory to be at different locations than that containing the code and fixed data. Sometimes it was only data.

'const' is anyway the wrong sort of attribute to use, as I've already explained. For example:

  const int A = rand();  // inside a function

A is written to multiple times at runtime. It can't go into actual read-only memory like a ROM. And it might have trouble going into a memory page with read-only attributes.

'const' tries to do too many things, most of them poorly, although it does a very good job at adding clutter.

--
bartc
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to