home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.lang.c:13708 sci.math:11522 comp.lang.misc:3092 comp.lang.fortran:3578 comp.std.c:2635
- Path: sparky!uunet!stanford.edu!rock!concert!duke!dsb
- From: dsb@duke.cs.duke.edu (D. Scott Bigham)
- Newsgroups: comp.lang.c,sci.math,comp.lang.misc,comp.lang.fortran,comp.std.c
- Subject: Re: Scientists as Programmers (was Re: Small Language Wanted)
- Message-ID: <716597823@romeo.cs.duke.edu>
- Date: 15 Sep 92 22:57:04 GMT
- References: <a_rubin.716225408@dn66 <1992Sep12.164915 <1992Sep15.043224.27920@nntpd.lkg.dec.com>
- Followup-To: comp.lang.c
- Organization: n. Arrangement in an orderly or logical fashion. See "miracle".
- Lines: 41
-
- From the Holy Book of <1992Sep15.043224.27920@nntpd.lkg.dec.com>
- as spake by diamond@jit.dec.com (Norman Diamond) :
-
- >In article <1992Sep12.164915.10734@jarvis.csri.toronto.edu> flaps@dgp.toronto.edu (Alan J Rosenthal) writes:
- >>a_rubin@dsg4.dse.beckman.com (Arthur Rubin) writes:
-
- >>>>>> int a, b; long c;
- >>>My interpretation (from reading K&R 2) would be that c = a * b should be
- >>>equivalent to c = (int)(a * b).
-
- >Mr. Rubin,
-
- Well, I'm not he, but your comments made me curious.
-
- > please state which section of the standard requires this.
- >If you cannot, then please at least quote the text in K&R 2 that led you to
- >this interpretation, so that we can see if K&R 2 has a bug that would be
- >worth recommending for correction and/or warning about.
-
- Section A7.6, "Multiplicative Operators", states that "The usual
- arithmetic conversions are performed on the operands, and predict the
- type of the result." Since a and b are both int's, the arithmetic
- conversions (described in section A6.5) predict that (a * b) should be as
- well.
-
- >>Indeed it is, but if that cast-to-int were to overflow you would get undefined
- >>behaviour on that account.
-
- >No, cast-to-int does not overflow. It has a defined result.
-
- Careful, this is _signed_ int we're talking about here. According to
- section A6.2, "Integral Conversions", "When any integer is converted to
- a signed type, the value is unchanged if it can be represented in the
- new type and is implementation-defined otherwise."
-
- -sbigham
- --
- Scott Bigham | The opinions expressed above are
- dsb@romeo.cs.duke.edu | (c) 1992 Hacker Ltd. and cannot be
- bigham@hercules.acpub.duke.edu | copied or distributed without a
- (but not for long) | Darn Good Reason(tm).
-