dip1000 rule 5
sclytrack
fake at hotmail.com
Mon Nov 26 09:10:23 UTC 2018
On Sunday, 25 November 2018 at 19:22:36 UTC, sclytrack wrote:
> There are 4 rules listed.
>
> https://github.com/dlang/DIPs/blob/master/DIPs/DIP1000.md
>
>
>
>
> What is rule 5?
>
>
> int* global_ptr;
>
> void abc() {
> scope int* a;
> int* b;
> scope int* c = a; // Error, rule 5
> scope int* d = b; // Ok
> int* i = a; // Ok, scope is inferred for i
> global_ptr = d; // Error, lifetime(d) <
> lifetime(global_ptr)
> global_ptr = i; // Error, lifetime(i) <
> lifetime(global_ptr)
> int* j;
> global_ptr = j; // Ok, j is not scope
> }
>
---
Are the following assumptions correct?
lifetime(a) < lifetime(b)
Means that b is older and lives longer than a. Or better, the
data that b is pointing
to is older and lives longer than the one that a is pointing too.
With the exception
of the null pointer which gets unlimited lifetime because it does
not corrupt memory.
---
scope int * a;
The variable gets unlimited lifetime because the value it is
pointing is assigned
null. And that throws exception when trying to access the memory
and because
it does not corrupt memory it is assigned unlimited lifetime.
Also once a variable
is assigned unlimited lifetime, then it retains that unlimited
lifetime during
the entire reachability of the variable.
scope int * c = a;
The above is allowed. You are assigning a variable that according
to the compiler
has unlimited lifetime. Therefore the variable c will be handled
like it has
unlimited lifetime by the compiler.
lifetime(c) <= lifetime(a)
The dip talks about longer and shorter, but is equal okay too?
int * c = a;
The above can not be inferred because scope is only inferred when
it is assigned
a limited lifetime. So it is an error.
---
How is a person able to understand this DIP?
---
How many DIP manager are there?
When is a DIP assigned a number?
---
More information about the Digitalmars-d-learn
mailing list