Manifest constant class instances
lngns
contact at lngnslnvsk.net
Sun Nov 4 22:31:48 UTC 2018
On Sunday, 4 November 2018 at 22:23:18 UTC, Alex wrote:
> On Sunday, 4 November 2018 at 22:06:28 UTC, Alex wrote:
>>>
>>> To make this point clearer: this works, but the instance
>>> doesn't live at runtime:
>>>
>>> ```
>>> class C { int foo() { return 123; } }
>>> enum i = new C().foo();
>>>
>>> void main()
>>> {
>>> import core.stdc.stdio;
>>> printf("%d\n", i); // i is a 123 literal
>>> }
>>> ```
>
> Or even better:
>
> ´´´
> class C
> {
> int member;
> int foo()
> {
> member++;
> return 123 + member;
> }
> }
>
> enum i = u();
> enum u = &(new C().foo);
>
> void main()
> {
> import std.stdio : writeln;
> writeln(i); // 124
> writeln(u()); // 125
> writeln(i); // 124
> writeln(u()); // 126
> }
> ´´´
So enum-delegates are stored in mutable memory at runtime?
Now this looks like a bug.
More information about the Digitalmars-d
mailing list