Proposal for design of 'scope' (Was: Re: Opportunities for D)

H. S. Teoh via Digitalmars-d digitalmars-d at puremagic.com
Tue Jul 15 07:58:52 PDT 2014


On Tue, Jul 15, 2014 at 09:19:34AM +0200, Jacob Carlborg via Digitalmars-d wrote:
> On 15/07/14 01:48, H. S. Teoh via Digitalmars-d wrote:
> 
> >Yes, but since the extent of this scope is unknown from inside the
> >function body, it doesn't easily lend itself nicely to check things
> >like this:
> >
> >	int* ptr;
> >	void func(scope int* arg) {
> >		ptr = arg; // should this be allowed?
> >	}
> >
> >If we only know that 'arg' has a longer lifetime than func, but we
> >don't know how long it is, then we don't know if it has the same
> >lifetime as 'ptr', or less. So it doesn't really let us do useful
> >checks.
> 
> I was thinking that "arg" would have at least the same lifetime as the
> caller, i.e. the same as "ptr".
[...]

But what if 'ptr' is declared in a private binary-only module, and only
the signature of 'func' is known? Then what should 'scope' mean to the
compiler when 'func' is being called from another module?


T

-- 
ASCII stupid question, getty stupid ANSI.


More information about the Digitalmars-d mailing list