www.digitalmars.com         C & C++   DMDScript  

D - optimizations?

reply "Pavel Minayev" <evilone omen.ru> writes:
The following program was compiled with optimizations
turned on (-O), but in debug mode (no -release):

    class foo
    {
        void bar() { }
    }

Compiler generated the following assembler code:

    L0:  call near ptr _Dinvariant__d_invariant_FC6ObjectZv
         call near ptr _Dinvariant__d_invariant_FC6ObjectZv
         ret

ROTFL =)
Jan 19 2002
parent reply "Walter" <walter digitalmars.com> writes:
What's happening is that a call to the class invariant is made at the
beginning and end of each public member function. -Walter

"Pavel Minayev" <evilone omen.ru> wrote in message
news:a2bq13$10i8$1 digitaldaemon.com...
 The following program was compiled with optimizations
 turned on (-O), but in debug mode (no -release):

     class foo
     {
         void bar() { }
     }

 Compiler generated the following assembler code:

     L0:  call near ptr _Dinvariant__d_invariant_FC6ObjectZv
          call near ptr _Dinvariant__d_invariant_FC6ObjectZv
          ret

 ROTFL =)
Jan 19 2002
parent reply "Pavel Minayev" <evilone omen.ru> writes:
"Walter" <walter digitalmars.com> wrote in message
news:a2cdql$1ep3$1 digitaldaemon.com...

 What's happening is that a call to the class invariant is made at the
 beginning and end of each public member function. -Walter
Yes, I know. But what's the reason in checking invariant for a function that does nothing? =) I think this should be optimized away...
Jan 19 2002
parent "Walter" <walter digitalmars.com> writes:
"Pavel Minayev" <evilone omen.ru> wrote in message
news:a2ched$1h26$1 digitaldaemon.com...
 "Walter" <walter digitalmars.com> wrote in message
 news:a2cdql$1ep3$1 digitaldaemon.com...

 What's happening is that a call to the class invariant is made at the
 beginning and end of each public member function. -Walter
Yes, I know. But what's the reason in checking invariant for a function that does nothing? =) I think this should be optimized away...
Ah, a very good question. And the answer (!) is that if that function is invoked via a pointer to a derived class object, then the invariant for that derived class needs to be run. You could argue that it doesn't need it on both entry and exit since no code is executed between them. You'd be correct.
Jan 19 2002