From: shang@corp.mot.com (David (Lujun) Shang)
Subject: Re: run-time type checking (was: Re: Covariant Types in Derived Classes)
Reply-To: shang@corp.mot.com
Organization: Motorola, Inc., Software Research and Development, Rolling Meadows, IL. 60008
Date: Wed, 29 Jul 92 16:05:46 GMT

In article <1992Jul28.214528.6360@ucc.su.OZ.AU> maxtal@extro.ucc.su.OZ.AU (John  
MAX Skaller) writes:
> In article <1992Jul27.170255.8185@cadsun.corp.mot.com> shang@corp.mot.com  
writes:
> >First of all, you must remember to override the virtual function in each  
> >derived class, and give the proper return value. If a forget to override, or   
> >if a give a name that happened to be the same name already exists, you make  
> >a trouble. The compiler has no way to help you to establish a proper name  
> >distribution.
> 
> 	The first is WRONG. Havent you ever head of PURE VIRTUAL FUNCTIONS????
>
Of cause I have. But remember, once you override a pure virtual function in a  
derived class, you may have further classes derived from the derived class  
where "Species" is no longer pure virtual! In fact I've already used what you  
suggested in my C++ programs, and I do have the trouble.
 
> >Secondly, you must remember to run time check the character strings returned 
> >by the virtual function. If you forget, you may put a cat and a rat 
> >together! The compiler has no way to help you essure the correct match!
> 
> 	The proposed RTTI downcast is WORSE: it return a NULL POINTER
> if the cast fails due to type mismatch on pointers.
>
No. The RTTI I suggested does not return any NULL pointers. Quite simple and  
safe, the compiler does not let you program pass if there is a potential type  
error. It seems that you did not read what I wrote carefully.
> >
> >Lastly, you leave much checking work that should be done at compile time to 
> >be done at run time. 
> 
> 	In this case maybe thats true. I dont see how
> the proposed RTTI/downcast is any different. It may have slightly
> better optimistaion oportunities, like all built in features.
>
Not just slightly. The compiler can know the specific type in many cases and  
hence can detect the type error at compile time. For those types unknown to the  
compiler, the compiler can also detect the type error through RTTI.  
> 
> >Type safe downcast with RTTI will not have the above problems:
> >
> 	WRONG. You get a system crash if you dont check for 0 pointer.
>
Angain, RTTI has nothing to do with null pointer. To return a null pointer for  
an RTT error is an irresponsible manner. At least, an exception should be  
raised for the error. I'm even not satisfied with the exception handling  
because you leave type error at run time! What I suggested is to detect all the  
type errors at compile time just by explicit run time type check. Sounds  
strange? I've mentioned this several times in my previous posters and examples  
are also given and I'm tired of repeating.

David Shang
 

 -- 
> ;----------------------------------------------------------------------
>         JOHN (MAX) SKALLER,         maxtal@extro.ucc.su.oz.au
> 	Maxtal Pty Ltd, 6 MacKay St ASHFIELD, NSW 2131, AUSTRALIA
> ;--------------- SCIENTIFIC AND ENGINEERING SOFTWARE ------------------
Newsgroups: comp.lang.c++,comp.std.c++