home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.lang.c++:11706 comp.std.c++:983
- Newsgroups: comp.lang.c++,comp.std.c++
- Path: sparky!uunet!munnari.oz.au!metro!extro.ucc.su.OZ.AU!maxtal
- From: maxtal@extro.ucc.su.OZ.AU (John MAX Skaller)
- Subject: Re: run-time type checking (was: Re: Covariant Types in Derived Classes)
- Message-ID: <1992Jul28.214528.6360@ucc.su.OZ.AU>
- Sender: news@ucc.su.OZ.AU
- Nntp-Posting-Host: extro.ucc.su.oz.au
- Organization: MAXTAL P/L C/- University Computing Centre, Sydney
- References: <1992Jul24.192207.15267@ucc.su.OZ.AU> <1992Jul27.170255.8185@cadsun.corp.mot.com>
- Date: Tue, 28 Jul 1992 21:45:28 GMT
- Lines: 69
-
- In article <1992Jul27.170255.8185@cadsun.corp.mot.com> shang@corp.mot.com writes:
- >> In article <1992Jul24.143359.3602@advtech.uswest.com> glw@io.uswest.com
- >(Glenn Williams) writes:
- >> >
- >> >Ok, let's have an example of a properly designed system.
- >
- >In article <1992Jul24.192207.15267@ucc.su.OZ.AU> maxtal@extro.ucc.su.OZ.AU
- >(John MAX Skaller) replies:
- >>
- >> But that wont PROVE anything. You have to give me
- >> an example of a system that uses downcasting and then I'll
- >> show how to write it without downcasting.
- >>
- >Your example "mate" is already a good example! And you did not provide a good
- >solution without downcasting. Using virtual function "Species()" can certainly
- >eliminates the necessity of downcast, but it introduces severe problems that a
- >safe downcast would never have.
- >
- >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????
-
- The second is a CONSEQUENCE of being able to
- chose the species name for each class. Thats
- DESIRABLE if you want to support multiple
- implementation of the same class.
-
- >
- >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.
-
- >
- >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.
-
-
- >On one head, you let down the run time performance. On the
- >other head, you leave errors that should be detected at compile time to the run
- >time.
- >
- >Type safe downcast with RTTI will not have the above problems:
- >
- >Firstly, the compiler will generate a proper type identifier for each type. The
- >detailed type information can be stored in files generated by the compiler, and
- >the library can provide a set of suitable functions to access these detail type
- >information through the type id. Howerver, for the purpose of downcast, only
- >the simple type id is needed. The programmer is never bothered by overriding a
- >virtual function that returns a character string or an interger that serves as
- >the type id. No error will be concerned about a mis-produced type id at run
- >time.
-
- WRONG. You get a system crash if you dont check for 0 pointer.
- --
- ;----------------------------------------------------------------------
- JOHN (MAX) SKALLER, maxtal@extro.ucc.su.oz.au
- Maxtal Pty Ltd, 6 MacKay St ASHFIELD, NSW 2131, AUSTRALIA
- ;--------------- SCIENTIFIC AND ENGINEERING SOFTWARE ------------------
-