null [re: spec#]

Simen kjaeraas simen.kjaras at gmail.com
Sun Nov 7 09:24:44 PST 2010


Roman Ivanov <isroman.DEL at ete.km.ru> wrote:

> I know what your mean, but the example is flawed:
>
> public void foo()
> {
>     if (m) {
>          Object p = new Object();
>          p.toString();
>     }
> }

You misunderstand. The idea is this:

void foo( ) {
   Object p;
   if ( m ) {
     p = new Object( );
     p.DoSomethingThatNeedsToBeDoneNow( );
   }
   // 20 lines of code here
   if ( m ) {
     p.doSomethingWeird( dataFromAbove );
   }
}

> int x = {
>     if (s == Dri.one)
>         return 1;
>     else if (s == Dri.two)
>         return 2;
>     else
>         return 3;
> }();
>
> This works. I'm not sure how efficient it is, but that would solve the
> issue with initialization without any path analysis.

I'm not sure the compiler actually does this, but it would be fairly
trivial to inline that delegate.


-- 
Simen


More information about the Digitalmars-d mailing list