Re: scope in function argument

2015-09-23 Thread Adam D. Ruppe via Digitalmars-d-learn

On Wednesday, 23 September 2015 at 17:09:40 UTC, Freddy wrote:

What does it mean when there is a scope in a function argument.


That you are not supposed to let that reference escape the 
function scope. The compiler does little verification of this 
right now, but may optimize on that assumption (notably, scope 
delegates will not be copied to the heap right now).


In the future, it may become an error to allow them to escape.

int* b;

void func(scope int* a) {
   b = a; // you made a escape the function scope, undefined 
behavior results

}



scope in function argument

2015-09-23 Thread Freddy via Digitalmars-d-learn

What does it mean when there is a scope in a function argument.
---
void func(scope int* a){}
---


Re: scope in function argument

2015-09-23 Thread Ali Çehreli via Digitalmars-d-learn

On 09/23/2015 10:11 AM, Adam D. Ruppe wrote:
> On Wednesday, 23 September 2015 at 17:09:40 UTC, Freddy wrote:
>> What does it mean when there is a scope in a function argument.
>
> That you are not supposed to let that reference escape the function
> scope.

Just to complete with a related feature, here are also 'return' 
parameters, which make the compiler ensure that the returned reference 
lives longer than the 'ref' argument. Unfortunately, I can't see that 
feature here anymore:


  http://dlang.org/function.html#parameters

Has it been pulled back? It still works in 2.068. I had written about it:


http://ddili.org/ders/d.en/function_parameters.html#ix_function_parameters.return,%20parameter

Then there is the -dip25 compiler switch that forces the programmer to 
put 'return' on every returned 'ref' parameter, effectively enforcing 
that check:


  http://wiki.dlang.org/DIP25

Ali