Newbie style question about string constants
cc
us86kj+3rxcwe3ebdv7w at grr.la
Thu Mar 27 06:20:25 UTC 2025
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
I got in the habit of using `static immutable` whenever possible
as enum just can't be trusted to use CTFE.
```d
enum string RfuncName = fullyQualifiedName!...
enum string funcName = RfuncName.crc32Of.toHexString(); // Oops!
Allocates on runtime every frame this is referenced
```
More information about the Digitalmars-d-learn
mailing list