November 04, 2018 Re: Manifest constant class instances | ||||
---|---|---|---|---|
| ||||
Posted in reply to kinke | On Sunday, 4 November 2018 at 21:26:23 UTC, kinke wrote:
> On Sunday, 4 November 2018 at 21:08:56 UTC, kinke wrote:
>> `enum c = new C()` doesn't imply that the instance lives at runtime too.
>
> 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
> }
> ```
This is kind of interesting...
´´´
import std.stdio;
class C
{
int member;
int foo()
{
member++;
return 123 + member;
}
}
enum i = new C().foo();
enum u = &(new C().foo);
void main()
{
import core.stdc.stdio;
printf("%d\n", i); // 124
writeln(u()); // 124
writeln(i); // 124
writeln(u()); // 125
}
´´´
|
November 04, 2018 Re: Manifest constant class instances | ||||
---|---|---|---|---|
| ||||
Posted in reply to Alex | 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
}
´´´
|
November 04, 2018 Re: Manifest constant class instances | ||||
---|---|---|---|---|
| ||||
Posted in reply to Alex | 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.
|
November 04, 2018 Re: Manifest constant class instances | ||||
---|---|---|---|---|
| ||||
Posted in reply to lngns | On Sunday, 4 November 2018 at 22:31:48 UTC, lngns wrote:
>
> So enum-delegates are stored in mutable memory at runtime?
> Now this looks like a bug.
Just followed the idea of pointer in the enum... Didn't think this is possible ;)
|
Copyright © 1999-2021 by the D Language Foundation