ref parameters: there is no escape

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Sun Aug 14 09:44:04 PDT 2011


On 8/14/11 10:28 AM, dsimcha wrote:
> I think this is an absolutely terrible idea, unless it has an "I know
> what I'm doing, let me cast away the safety" loophole.

I'm weary of absolute qualifications, particularly after arguments have 
been made in favor of the idea that are not refuted.

> Consider the case
> of designing a D wrapper for C functionality.
>
> // C, we know it doesn't escape its parameters but the compiler doesn't.
> void cFun(int* a, int* b);
>
> // D:
> void dWrapper(ref int a, ref int b) {
> cFun(&a, &b);
> }

I understand. Probably it's fine to require an explicit cast for taking 
the address. Offhand, I don't see this as a frequent situation, or one 
that would make pass-by-pointer unpalatable.

> If you want the compiler to put extra restrictions on you in the name of
> safety, that's what SafeD is for. If you're writing an @system function,
> then the compiler should stay out of your way and let you do what you
> want, unless it can **prove** that it's wrong.

The problem is, currently all functions that pass locals by ref cannot 
be proven safe modularly.


Andrei


More information about the Digitalmars-d mailing list