home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / std / c / 2637 < prev    next >
Encoding:
Internet Message Format  |  1992-09-15  |  3.8 KB

  1. Xref: sparky comp.std.c:2637 comp.lang.c:13710
  2. Newsgroups: comp.std.c,comp.lang.c
  3. Path: sparky!uunet!decwrl!pa.dec.com!nntpd2.cxo.dec.com!nntpd.lkg.dec.com!jit345.bad.jit.dec.com!diamond
  4. From: diamond@jit345.bad.jit.dec.com (Norman Diamond)
  5. Subject: Re: Scientists as Programmers (was Re: Small Language Wanted)
  6. Message-ID: <1992Sep16.014635.27449@nntpd.lkg.dec.com>
  7. Followup-To: comp.std.c,comp.lang.c
  8. Sender: usenet@nntpd.lkg.dec.com (USENET News System)
  9. Reply-To: diamond@jit.dec.com (Norman Diamond)
  10. Organization: Digital Equipment Corporation Japan , Tokyo
  11. References: <92Sep1.205116edt.669@neuron.ai.toronto.edu> <1992Sep4.162938.29237@dscomsf.desy.de> <Bu2r42.5xr@mentor.cc.purdue.edu> <id.I12T.GP4@ferranti.com> <a_rubin.716152347@dn66> <1992Sep11.012559.17662@nntpd.lkg.dec.com> <a_rubin.716225408@dn66  <1992Sep12.164915.10734@jarvis.csri.toronto.edu> <1992Sep15.043224.27920@nntpd.lkg.dec.com> <a_rubin.716593540@dn66> <716597823@romeo.cs.duke.edu>
  12. Date: Wed, 16 Sep 1992 01:46:35 GMT
  13. Lines: 60
  14.  
  15. In article <a_rubin.716593540@dn66> a_rubin@dsg4.dse.beckman.com (Arthur Rubin) writes:
  16. >In <1992Sep15.043224.27920@nntpd.lkg.dec.com> diamond@jit345.bad.jit.dec.com (Norman Diamond) writes:
  17. >>In article <1992Sep12.164915.10734@jarvis.csri.toronto.edu> flaps@dgp.toronto.edu (Alan J Rosenthal) writes:
  18. >>>a_rubin@dsg4.dse.beckman.com (Arthur Rubin) writes:
  19. >>>>>>>>>>>>>>>>>>>>>>>>>>>>>    int a, b;   long c;
  20. >>>>My interpretation (from reading K&R 2) would be that c = a * b should be
  21. >>>>equivalent to c = (int)(a * b).
  22.  
  23. >K&R 1, in the section on type conversions (2.7), states:
  24. >    The result is of the higher type....
  25.  
  26. without quite mentioning what happens when neither operand needed promoting :-)
  27. No problem though; there's more below.
  28.  
  29. >This implies that the result in case of overflow, although undefined, is
  30. >an undefined int.
  31.  
  32. No.  When a result is undefined, the computer is allowed to burn itself up
  33. and be reincarnated with a different program in its memory, in which the
  34. declared datatypes have magically changed to "long".
  35.  
  36. (If the result were unspecified, it would be an unspecified int.  But the
  37. standard does not say this -- likely because overflow can at least cause
  38. your thread of execution to burn up, and maybe be reincarnated with a
  39. change of datatype :-)
  40.  
  41. >Followups to comp.std.c, as it no longer is relevant to any of the other
  42. >groups.
  43.  
  44. Yeah, and Mr. Bigham tried to trick me into posting to comp.lang.c (without
  45. warning), so I've added comp.lang.c back in for Mr. Bigham.
  46.  
  47. In article <716597823@romeo.cs.duke.edu> dsb@duke.cs.duke.edu (D. Scott Bigham) writes:
  48. >Section A7.6, "Multiplicative Operators", states that "The usual
  49. >arithmetic conversions are performed on the operands, and predict the
  50. >type of the result."
  51.  
  52. OK, I can find in ANSI 3.2.1.5, page 36 lines 17 to 18, "and yield result
  53. types in a similar way.  The purpose is to yield a common type, which is
  54. also the type of the result."  Couldn't find anything like this in the
  55. expressions chapter though.
  56.  
  57. Oddly, the last two lines in that section (and on that page) allow
  58. implementations to stick extra bits in floating values, without saying
  59. anything about integral values.
  60.  
  61. >>No, cast-to-int does not overflow.  It has a defined result.
  62.  
  63. >Careful, this is _signed_ int we're talking about here.  According to
  64. >section A6.2, "Integral Conversions", "When any integer is converted to
  65. >a signed type, the value is unchanged if it can be represented in the
  66. >new type and is implementation-defined otherwise."
  67.  
  68. Sounds like it agrees with the standard.  Sometimes the result is defined
  69. by the standard, the rest of the time the result is defined by the
  70. implementation, and the result is never undefined.
  71. --
  72. Norman Diamond       diamond@jit081.enet.dec.com
  73. If this were the company's opinion, I wouldn't be allowed to post it.
  74. "Yeah -- bad wiring.  That was probably it.  Very bad."
  75.