public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: Turning off C++ casting?
@ 2003-02-20 10:05 Paolo Bonzini
  2003-02-20 10:19 ` Gabriel Dos Reis
  0 siblings, 1 reply; 17+ messages in thread
From: Paolo Bonzini @ 2003-02-20 10:05 UTC (permalink / raw)
  To: gcc; +Cc: mongryong

> But if I'm iterating over lots of
> objects, I'd like to get rid off the cost of dynamic_cast when I know
> for sure the objects will always be of this type.

assert and the pointer version of dynamic_cast are your friends if you don't 
want #ifdefs.

  assert (dynamic_cast<ExtendedObject*>(&baseObj) != NULL);
  ExtendedObject& obj = *reinterpret_cast<ExtendedObject*>(&baseObj);

> What I want to know is whether GCC allows you to optimize
> 'dynamic_cast'ing: gcc -fno_dynamic_cast ....  I don't think gcc has
> such a switch.

Maybe -fno-rtti (along with disabling much more)?

Paolo

^ permalink raw reply	[flat|nested] 17+ messages in thread
* Turning off C++ casting??
@ 2003-02-19 23:15 Mongryong
  2003-02-19 23:37 ` Jack Lloyd
  0 siblings, 1 reply; 17+ messages in thread
From: Mongryong @ 2003-02-19 23:15 UTC (permalink / raw)
  To: gcc

Is there a way to disable C++ casting?  That is, during
development/debugging I like using C++ casts like dynamic_cast to ensure
my parameters are correct.  However, for a release build where I'm
confident 'all down-casting' is safe, I would like the casting to be
turn off - that is, something similar to 'C' type casting:

// Debug build
void func(BaseObject& obj) {
  ExtendedObject& obj = dynamic_cast<ExtendObject&>(obj);   
//...
}

// Release build
void func(BaseObject& obj) {  
  ExtendedObject& obj = *((ExtendObject*)((void*)arg)); // release build
//...
}

Correct me if I'm wrong, but I believe the release build is faster.



^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2003-03-04 16:01 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <B11C8538-4464-11D7-B22E-003065A77310@apple.com>
2003-02-20  0:24 ` Turning off C++ casting?? Mongryong
     [not found]   ` <20030219174232.A21518@synopsys.com>
2003-02-20  2:33     ` Mongryong
2003-02-20  9:54       ` Vladimir Merzliakov
2003-02-20 10:05 Turning off C++ casting? Paolo Bonzini
2003-02-20 10:19 ` Gabriel Dos Reis
2003-02-20 12:18   ` Paolo Bonzini
2003-02-20 12:21     ` Vladimir Merzliakov
2003-02-20 12:45       ` Paolo Bonzini
2003-02-20 18:00       ` Jack Lloyd
2003-02-20 12:28     ` Gabriel Dos Reis
2003-02-20 12:56       ` Paolo Bonzini
2003-02-20 13:22         ` Gabriel Dos Reis
2003-02-20 17:26           ` Mongryong
2003-03-04 16:29           ` Paolo Bonzini
  -- strict thread matches above, loose matches on Subject: below --
2003-02-19 23:15 Turning off C++ casting?? Mongryong
2003-02-19 23:37 ` Jack Lloyd
2003-02-19 23:43   ` Mongryong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).