Is there any real reason to use "const"?
H. S. Teoh
hsteoh at quickfur.ath.cx
Mon Jan 24 20:11:36 UTC 2022
On Mon, Jan 24, 2022 at 12:02:11PM -0800, Walter Bright via Digitalmars-d wrote:
> On 1/24/2022 8:43 AM, rempas wrote:
> > Read only memory? So in the same place where string literals are
> > placed? This sounds cool and it's really something considerable!
> > Does this offer things like security as date will be able to be
> > created once and not get modified again? I hope I'm not asking for
> > too much...
> You can see this if you run an object file disassembler over the
> compiler output, the immutable data goes in read-only sections.
It depends on OS support, obviously. But most commonly-used OSes ought
to support this.
Placing static string data in the read-only segment could be one line of
defense against exploits that, e.g., modify an embedded shell script to
do something pernicious instead.
Elegant or ugly code as well as fine or rude sentences have something in common: they don't depend on the language. -- Luca De Vitis
More information about the Digitalmars-d