Is there any real reason to use "const"?
Steven Schveighoffer
schveiguy at gmail.com
Mon Jan 24 19:09:18 UTC 2022
On 1/24/22 10:44 AM, Walter Bright wrote:
> On 1/24/2022 6:40 AM, Steven Schveighoffer wrote:
>> immutable/const is purely a compile-time concept. It's not reflected
>> in the final binary, so it's not necessary to forward the attributes
>> to a language that doesn't support it.
>
> Immutable global data gets placed in read-only memory sections.
> Read-only memory sections are nice in a demand-paged virtual system, as
> the pages they are in never have to be copied because they are never
> marked as "dirty".
Sure, but const isn't necessary for that. Const is a compiler construct
to prevent you from doing stupid things. But a programming language can
run perfectly fine with ROM without having a const concept.
D1 put string literals in ROM without const.
-Steve
More information about the Digitalmars-d
mailing list