Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!softrue!kearns From: kearns@softrue.UUCP (Steven Kearns) Newsgroups: comp.lang.c++ Subject: Re: typesafe downward casting Message-ID: <18.UUL1.3#8618@softrue.UUCP> Date: 1 Apr 91 16:17:14 GMT References: <1991Mar30.161252.26129@kodak.kodak.com> Organization: Software Truth Lines: 39 > From: cok@islsun.Kodak.COM (David Cok) > Subject: Re: typesafe downward casting > .... >And if you can prove that global variables are used correctly, and goto's,and > case statements or types, you should not feel guilty??? Some constructs are > error-inviting -- cast is one of them -- and are best avoided. If you need > to use them, you have to be very careful, but if a program has a lot of them > bugs are likely. Yes, if you can prove that your goto is correct, you should feel very satisfied. The only reason to avoid these statements, as Djikstra would say, is because they complicate the proof of correctness. It seems to me that knowing that a Base* actually points to a Derived* is about as trivial as knowing that a number is non-negative. If you cannot handle this, I suggest taking up a different profession ;-}. > >If we added stuff to C++ to take care of this "problem", then we would > >also have to add new types so that people do not call sqrt(x) when > >x is a negative number, or so they do not call a/b when b is 0. > > > No, you don't have to. Every language is a trade-off between what is checked > at compile-time, what is checked at run-time, and what is left to cause core > dumps, often at places far from the original problem. People differ as to > what should be in which category -- .... > I think that a type-safe downcast is a legitimate thing to consider > supporting at run-time. That is the point: there is no compelling reason to include it in the language except for your opinion. Why make type-safe downcasts but non-type-safe division? Fortunately, C++ gives you enough tools so that you can ensure type-safe downcasting if you want, while I can avoid them if I want. -steve ******************************************************** * Steven Kearns ....uunet!softrue!kearns * * Software Truth softrue!kearns@uunet.uu.net * ********************************************************