You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by "mario.gonzalez" <ma...@avega.se> on 2002/09/27 14:30:41 UTC

dynamic_cast on Grammar fails

Hi, 

After a code review, we decided to change the line ("rootGrammar" is of type "Grammar*"):

SchemaGrammar* grammar = (SchemaGrammar*)rootGrammar;

to: 

SchemaGrammar* grammar = dynamic_cast<SchemaGrammar*>(rootGrammar);

As, we believe that using dynamic_cast (we're developing on the win32 platform, with vc6), is the most correct way to cast between types in the same inheritance chain (we use dynamic_cast exclusively in our project). 

The only problem is that the latter method fails (whereas the former method never failed), throwing an exception and returning 0, and yes, the "Grammar" object we're trying to down-cast is fully initialized. The compiler options are set to support RTTI, so I'm really failing to see what's wrong here. The stack at the time of failure looks as follows:

KERNEL32! 77e8f142()
MSVCRTD! _CxxThrowException@8 + 57 bytes
MSVCRTD! __RTDynamicCast + 383 bytes
rfw::XMLPLCBuilder::createDataTypeMapping() line 335 + 23 bytes

It is impossible to trace into the dynamic_cast, so it seems I'm left with very few options on how to go about to fix this, or at least understand why this fails. Has anybody else experienced this?

Everything seems ok, the Grammar class is abstract, and seems to be a polymorphic type, and no warnings or errors occur at compile-time.

Any hints or tips are greatly appreciated

Cheers

Mario 

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


Re: dynamic_cast on Grammar fails

Posted by Vijay Ganapati <vi...@clarussystems.com>.
you may have to choose RTTI options on in settings.
It is not on by default in the environment.
I personally try to avoid using rtti, because of performance hit. you can
also get by with static_cast and reinterpret_cast, should you choose to...

vijay
----- Original Message -----
From: "mario.gonzalez" <ma...@avega.se>
To: <xe...@xml.apache.org>
Sent: Friday, September 27, 2002 5:30 AM
Subject: dynamic_cast on Grammar fails


> Hi,
>
> After a code review, we decided to change the line ("rootGrammar" is of
type "Grammar*"):
>
> SchemaGrammar* grammar = (SchemaGrammar*)rootGrammar;
>
> to:
>
> SchemaGrammar* grammar = dynamic_cast<SchemaGrammar*>(rootGrammar);
>
> As, we believe that using dynamic_cast (we're developing on the win32
platform, with vc6), is the most correct way to cast between types in the
same inheritance chain (we use dynamic_cast exclusively in our project).
>
> The only problem is that the latter method fails (whereas the former
method never failed), throwing an exception and returning 0, and yes, the
"Grammar" object we're trying to down-cast is fully initialized. The
compiler options are set to support RTTI, so I'm really failing to see
what's wrong here. The stack at the time of failure looks as follows:
>
> KERNEL32! 77e8f142()
> MSVCRTD! _CxxThrowException@8 + 57 bytes
> MSVCRTD! __RTDynamicCast + 383 bytes
> rfw::XMLPLCBuilder::createDataTypeMapping() line 335 + 23 bytes
>
> It is impossible to trace into the dynamic_cast, so it seems I'm left with
very few options on how to go about to fix this, or at least understand why
this fails. Has anybody else experienced this?
>
> Everything seems ok, the Grammar class is abstract, and seems to be a
polymorphic type, and no warnings or errors occur at compile-time.
>
> Any hints or tips are greatly appreciated
>
> Cheers
>
> Mario
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
>
>


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