On Monday, 24 February 2025 at 16:07:07 UTC, Ian wrote:
Hello,

What's the recommended D way to declare a string constant? Say, for example, for a path used inside a class constructor? I've seen const string, immutable, enum etc...

Is this the place for these kinds of questions? Is there a D stack overflow?

Cheers,
 Ian

For string constants you’ll usually want to mark them as `static immutable`. Strings with this combination will usually be put into read-only sections (ROM) of the resulting binaries.

Unlike `static immutable` which specifies that data exists once in a specific location, `enum` (“compile-time constant”) is more similar to copy & paste where the compiler inserts the value into each location where it is referred to.

Reply via email to