home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / cplus / 12589 < prev    next >
Encoding:
Text File  |  1992-08-19  |  2.5 KB  |  59 lines

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