[prev in list] [next in list] [prev in thread] [next in thread] 

List:       xerces-c-dev
Subject:    RE: Usage of C-style cast while downcasting.
From:       "Michael Kochetkov" <Michael.Kochetkov () synartra ! com>
Date:       2005-03-29 18:35:52
Message-ID: 200503291836.WAA20760 () relay1 ! synartra ! com
[Download RAW message or body]

> Hi Michael,
Hi, Axel,

> I use to take 'static_cast' in order to obtain a 
> DOMElement-pointer from a DOMNode-pointer. But usually I 
> check the type of the node actually to be 
> DOMNode::ELEMENT_NODE before performing the cast.
I use reinterpret_cast in my code sometimes just because it is ugly enough
to draw attention to itself. I almost always consider it as a matter to
change either implementation or architecture.

> static_cast is a weaker concept than dynamic_cast, sure. 
> However, static_cast is a stronger concept than 
> reinterpret_cast, since the compiler can check if there is a 
> descent relationship between the types.
You are right. It shall do the job provided there are no virtual bases and
no pointers that point the other objects we believe.

> BTW: do there exist any C++-compilers which do not understand 
> static_cast?
I believe all modern (and not that modern) compilers understand xxx_cast
expressions. But there likely to be some bugs in implementations (off the
top of my head I can recall some known problems with exact type
determination in exception specifications). So, for general purpose
libraries like Xerces is it is considered to be OK not to rely upon the
language (at least for C++) built-in dynamic types support.

Thanks a lot for your help.
--
Michael Kochetkov.


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic