home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / std / c / 3203 < prev    next >
Encoding:
Text File  |  1992-12-14  |  3.0 KB  |  65 lines

  1. Newsgroups: comp.std.c
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!cs.utexas.edu!swrinde!elroy.jpl.nasa.gov!decwrl!deccrl!news.crl.dec.com!rdg.dec.com!uvo.dec.com!e2big.mko.dec.com!jrdzzz.jrd.dec.com!jit533.jit.dec.com!diamond
  3. From: diamond@jit533.jit.dec.com (Norman Diamond)
  4. Subject: Re: Is INT_MAX<<1 defined?
  5. Message-ID: <Bz8MtG.479@jrd.dec.com>
  6. Sender: usenet@jrd.dec.com (USENET News System)
  7. Nntp-Posting-Host: jit533.jit.dec.com
  8. Reply-To: diamond@jit.dec.com (Norman Diamond)
  9. Organization: Digital Equipment Corporation Japan , Tokyo
  10. References: <1992Dec1.050540 <1992Dec8.1 <Bz35no.J6M@jrd.dec.com> <8322@charon.cwi.nl>
  11. Date: Mon, 14 Dec 1992 07:15:16 GMT
  12. Lines: 51
  13.  
  14. In article <8322@charon.cwi.nl> dik@cwi.nl (Dik T. Winter) writes:
  15. >What it comes down to is that << is not a mathematical operation, there
  16. >is nothing in mathematics that tells us that 16384 << 1 equals 32768.
  17.  
  18. Additional non-mathematical operations:
  19.   ++ (prefix and postfix)
  20.   -- (prefix and postfix)
  21.   [] (subscript, C definition using pointers)
  22.   () (function call, C definition using pointers)
  23.   () (cast)
  24.   unary  &  *  !
  25.   unary  ~  on a value that is not a single bit
  26.   binary /  on integral values where the mathematical quotient is not integral
  27.   binary .  ->  sizeof  %  &  ^  |  &&  ||  =  *=(etc.)  ,
  28.  
  29. >So what is the meaning of:
  30. >1.  Operation on value in this case?
  31.  
  32. Operations have meanings defined in the C standard.  For "value", it looks
  33. like we have to refer to another standard.  The ANSI C standard, section 1.6,
  34. page 4 lines 3 to 5, says:  "Terms not defined in this Standard are to be
  35. interpreted according to the American National Dictionary for Information
  36. Processing Systems, Information Processing Systems Technical Report ANSI
  37. X3/TR-1-82 (1982)."  I don't know the ISO equivalent.
  38.  
  39. >    Where in the standard does it tell
  40. >    us that for signed (16 bit) int 16384, 16384 << 1 is 32768?
  41.  
  42. I think the standard is unclear enough to recommend an interpretation ruling.
  43. However, for comparison, for unsigned types, the standard says explicitly
  44. that the value of the result is a mathematical multiplication followed by
  45. a mathematical modulo reduction -- if it were a representation multiplication,
  46. the modulo reduction would have been a no-op and would not have been stated.
  47.  
  48. >    Is an implementation not allowed to define it as -32768?  Or whatever?
  49.  
  50. Implementations are allowed to define what happens when signed results don't
  51. fit in the corresponding types.  They aren't REQUIRED to, that's all.
  52.  
  53. >    But in all there is no definition in *mathematics* for this operation.
  54. [...]
  55. >The bottom-line is that shifting is not a mathematical concept, [...]
  56.  
  57. That didn't prevent a ton of other C operations from being defined on
  58. mathematical values.  Actually maybe the standards committees can start
  59. to get an idea of just how unpopular this stunt is.  However, that is what
  60. they did, following the path of other language committees.
  61. --
  62. Norman Diamond       diamond@jit081.enet.dec.com
  63. If this were the company's opinion, I wouldn't be allowed to post it.
  64. "It's been a lovely recession."
  65.