Newsgroups: comp.software-eng,comp.object,comp.lang.eiffel,comp.lang.smalltalk,comp.lang.modula3,comp.lang.objective-c
Path: cantaloupe.srv.cs.cmu.edu!das-news.harvard.edu!news2.near.net!MathWorks.Com!solaris.cc.vt.edu!uunet!mole-end!mat
From: mat@mole-end.matawan.nj.us
Subject: Re: Static vs Dynamic Typing: Effects on Productivity?
Message-ID: <1994Sep1.053009.19271@mole-end.matawan.nj.us>
Organization: :
References: <DERWAY.94Aug23180251@alumni.ndc.com> <33u5un$ppr@vienna.eiffel.com> <340dcc$qn8@larry.rice.edu>
Date: Thu, 1 Sep 1994 05:30:09 GMT
Lines: 33
Xref: glinda.oz.cs.cmu.edu comp.software-eng:25291 comp.object:19966 comp.lang.eiffel:6261 comp.lang.smalltalk:16118 comp.lang.modula3:2937 comp.lang.objective-c:3011

In article <340dcc$qn8@larry.rice.edu>, amitp@owlnet.rice.edu (Amit Jayant Patel) writes:

> I have often heard that "most" C++ programs use casts.  However, I
> haven't found any place where I needed them, other than const-casts,
> which are no longer needed with the 'mutable' keyword.
> 
> Can someone give examples of where casts are necessary in C++?  I have
> not worked on medium or large programs yet, so I may just be lacking
> experience.

I suspect that the author was accustomed to using C++ as though it were
Smalltalk and downcasting to get at a `universal' base class.  (Of course,
I could be entirely wrong.)

There _are_ some places where you end up writing _conversions_ (which get
expressed as casts); these typically are places where you need more
conversions than C++ will insert automatically, or where you need to
disambiguate.

Such casts are dangerous not because they violate the type system, but
because they might violate it someday when declarations are changed.  It
is for this reason that ANSI/ISO C++ will (almost certainly) contain
the `static_cast< T >( .. .. .. )' which will convert its parameter to
the type  T  _iff_ it can be done by a legal, legitimate conversion (e.g.
if the compiler could insert the conversion itself, if it knew your
intentions).  If such a conversion attempts to contravene the type system,
it is illegal and will be diagnosed.

-- 
 (This man's opinions are his own.)
 From mole-end				Mark Terribile
 mat@mole-end.matawan.nj.us, Somewhere in Matawan, NJ
	(Training and consulting in C, C++, UNIX, etc.)
