Is there any real reason to use "const"?

H. S. Teoh hsteoh at
Mon Jan 24 20:09:46 UTC 2022

On Mon, Jan 24, 2022 at 11:59:37AM -0800, Walter Bright via Digitalmars-d wrote:
> On 1/24/2022 7:44 AM, Walter Bright wrote:
> Also, immutable data can be merged together, reducing the memory
> footprint.  The dmd compiler does this with strings, for example.
> Identical string literals are set up to get merged at link time, this
> can only happen if they are immutable.
> Immutable zero initialized data also gets merged. A zero is a zero, no
> matter what type it is!

Makes me curious: how feasible is it to have functions with identical
bodies merge together as well? This would help reduce template bloat
when you have e.g. a templated type where a bunch of functions are
identical because they either don't depend on the type (e.g. a container
method that doesn't care about what type the payload is), or else depend
on type traits that are common across many types (e.g., int.sizeof which
is shared with uint.sizeof, float.sizeof, etc.).


Why is it that all of the instruments seeking intelligent life in the universe are pointed away from Earth? -- Michael Beibl

More information about the Digitalmars-d mailing list