Re: Implementation of static_cast<>

Alain Miniussi <alainm@cup.hp.com>
17 Jan 2002 00:29:27 -0500

          From comp.compilers

Related articles
Implementation of static_cast<> bgera@hotmail.com (2002-01-14)
Re: Implementation of static_cast<> alainm@cup.hp.com (Alain Miniussi) (2002-01-17)
Re: Implementation of static_cast<> vbdis@aol.com (2002-01-17)
| List of all articles for this month |

From: Alain Miniussi <alainm@cup.hp.com>
Newsgroups: comp.compilers
Date: 17 Jan 2002 00:29:27 -0500
Organization: HP
References: 02-01-056
Keywords: C++
Posted-Date: 17 Jan 2002 00:29:27 EST

Bond wrote:
> Im curious to know the implementation of static_cast<> by the C++ compiler.
> Since it is a better version than "C" style casts...
>
> I assume something like:
>
> 1) try to get the type of the non-polymorphic object. something like "typeid()"
> 2) try to match the given pointer/type to the type of the template parameter
> 3) If success return after casting ( "C" style ? ) else return null.


That's dynamic_cast<> (applied to pointers).
static_cast<>, when it can be used, works like the C cast, the compiler just
check for some constraints on the types at compile time.
You can take a look at any C++ book for more details.


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.