home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- From: nikki@trmphrst.demon.co.uk (Nikki Locke)
- Path: sparky!uunet!pipex!demon!trmphrst.demon.co.uk!nikki
- Distribution: world
- Subject: Re: Covariant Types in Derived Classes
- References: <1992Aug13.162956.10279@mole-end.matawan.nj.us>
- X-Mailer: cppnews $Revision: 1.14 $
- Organization: Trumphurst Ltd.
- Lines: 45
- Date: Tue, 18 Aug 1992 20:00:17 +0000
- Message-ID: <714193217snx@trmphrst.demon.co.uk>
- Sender: usenet@gate.demon.co.uk
-
-
- In article <1992Aug13.162956.10279@mole-end.matawan.nj.us> mat@mole-end.matawan.nj.us writes:
-
- > In article <713504630snx@trmphrst.demon.co.uk>, nikki@trmphrst.demon.co.uk (Nikki Locke) writes:
- > > By the way, what is
- > > int x;
- > > long z;
- > >
- > > x = (int)z;
- > >
- > > Is this a cast, or a conversion ? (I want a warning anyway, please).
- >
- > It is a conversion that is indicated syntactically by a cast.
- >
- > Why do you want a warning? You asked for it explicitly and it lies
- > within the type system. There's an important principle here: for
- > every construct that can produce a warning, there must be a way to
- > write an equivalent construct that does _not_ produce the warning.
- > This is part and parcel of the C/C++ philosophy that ``if you _really_
- > want to do that, we'll take you at your word.''
- >
- > The code fragment written _without_ the cast might very well merit a
- > warning about value truncation.
- You are quite right. In this case, it is legal to write
- x = z; // Give me a warning please
- x = (int)z; // I really mean it, don't warn me
-
- However, there are many cases where the cast syntax is _necessary_ (e.g.
- to distinguish between multiple user-defined conversions). To have the
- compiler accept all such casts without warning (because cast means "I
- really mean it") is unfortunate - I might have typed the wrong thing.
-
- I think what I am asking for is some kind of language syntax which
- distinguishes between casts which I expect to be safe [conversions] (so I
- hope the compiler will warn me if they aren't), and those which I know
- aren't safe [coercions] (but I want to do it anyway, because of some
- additional knowledge I possess which the compiler can't see).
-
- What does the team think ?
- ---
- Nikki Locke | | nikki@trmphrst.demon.co.uk
- Trumphurst Ltd. | Tel: +44 (0)691-670318 | nikki@cix.compulink.co.uk
- PC and Unix consultancy | Fax: +44 (0)691-670316 | nikki@kewill.co.uk
- trmphrst.demon.co.uk is NOT affiliated with ANY other sites at demon.co.uk.
- Demon.co.uk is a dial-up subscription access point to the Internet.
-