preparing for const, final, and invariant

Walter Bright newshound1 at digitalmars.com
Thu May 17 19:38:58 PDT 2007


Manfred Nowak wrote:
> Walter Bright wrote
> 
>> scope - the function will not keep a reference to the parameter's
>> data that will persist beyond the scope of the function
> 
>>     g = a;	// error, a is scope
> 
> In this example the function assigns to a variable living outside of 
> the scope of the function. Therefore the function does not keep that 
> reference itself---and that rule should not fire.

Since it's storing a reference that will "persist beyond the scope of 
the function", it's illegal.

> In addition: if the rule's wording is changed to match that example, 
> then it becomes unclear, whether `writefln( &a)' is allowed because 
> `writefln' might store that reference somewhere---especially via OS in 
> a file, which might be read in later by the calling process.
> 
> In case of disallowance that rule would disallow printing too.

Making copies is allowed.



More information about the Digitalmars-d-announce mailing list