ref parameters: there is no escape

Timon Gehr timon.gehr at gmx.ch
Mon Aug 15 14:04:23 PDT 2011


On 08/15/2011 04:04 PM, Mehrdad wrote:
> On 8/15/2011 4:10 AM, Timon Gehr wrote:
>> On 08/15/2011 08:16 AM, Mehrdad wrote:
>>> (1) I thought the whole point of D was that you didn't need pointers to
>>> program effectively?
>>
>> Why would the change contradict this?
> Because now you need pointers to pass things by reference?

Only if the function intends to escape the reference. And if you really 
need to, you can still use a cast. Furthermore, escaping a reference is 
generally unsafe when it is to stack memory (they can be some 
higher-level invariant that guarantees safety, but that is not within 
the compilers reach -- use a cast.)

When the reference is to a value type on heap memory, you had pointers 
in your code all along.
>
>>> (2) Isn't this what compiler **warnings** are for?
>> In a well designed language, warnings are useless.
> ?!?!??!!
>
> You've never used C#/C/Java/whatever? Or do you think they're all poorly
> designed?

Warnings are issued for constructs that are regarded as potentially 
dangerous/error-prone by many people, but are still valid code. 
Therefore, they usually reflect suboptimal language design.




More information about the Digitalmars-d mailing list