Thread overview | |||||
---|---|---|---|---|---|
|
September 23, 2015 scope in function argument | ||||
---|---|---|---|---|
| ||||
What does it mean when there is a scope in a function argument. --- void func(scope int* a){} --- |
September 23, 2015 Re: scope in function argument | ||||
---|---|---|---|---|
| ||||
Posted in reply to Freddy | 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
}
|
September 23, 2015 Re: scope in function argument | ||||
---|---|---|---|---|
| ||||
Posted in reply to Adam D. Ruppe | 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 |
Copyright © 1999-2021 by the D Language Foundation