home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / c / 11606 < prev    next >
Encoding:
Internet Message Format  |  1992-07-25  |  1.8 KB

  1. Path: sparky!uunet!sun-barr!ames!agate!dog.ee.lbl.gov!horse.ee.lbl.gov!torek
  2. From: torek@horse.ee.lbl.gov (Chris Torek)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: semantics of "<=" change in ANSI C?
  5. Date: 26 Jul 1992 01:17:54 GMT
  6. Organization: Lawrence Berkeley Laboratory, Berkeley
  7. Lines: 34
  8. Message-ID: <24898@dog.ee.lbl.gov>
  9. References: <24365@dog.ee.lbl.gov> <1992Jul8.185753.13780@chinet.chi.il.us> <24686@dog.ee.lbl.gov> <1992Jul20.155649.7791@chinet.chi.il.us>
  10. Reply-To: torek@horse.ee.lbl.gov (Chris Torek)
  11. NNTP-Posting-Host: 128.3.112.15
  12.  
  13. In article <1992Jul20.155649.7791@chinet.chi.il.us>
  14. les@chinet.chi.il.us (Leslie Mikesell) writes:
  15. >... maybe I just have a broken compiler since it seems to handle constant
  16. >initializers differently than the same values at runtime.
  17. >
  18. >For example:
  19. >#include termio.h
  20. >main()
  21. >{
  22. >unsigned short a = ~CBAUD;
  23. >....
  24. >}
  25. >gives me an error "initializer does not fit: -16" unless I add a
  26. >cast, but moving the assignment to runtime does what I expected
  27. >even without a cast.  Is that normal?
  28.  
  29. If the error is merely a warning, the compiler may still conform to
  30. the ANSI C standard.  If it stops compilation, the compiler is broken.
  31. Assignment to an unsigned causes truncation modulo some power of two,
  32. the exact power depending on the maximum value for variables of that
  33. unsigned type, so even
  34.  
  35.     unsigned short a = -16;
  36.  
  37. is legal, setting a to 65520 on typical current machines.
  38.  
  39. In this particular case, a warning is probably a disservice, although
  40. there may be counterexamples.  (For instance, under the BSD
  41. implementation of POSIX termios, the c_cflag field has type `unsigned
  42. long'.  On the other hand, the BSD implementation has no CBAUD: tty
  43. baud rates are just integers, as they should always have been.)
  44. -- 
  45. In-Real-Life: Chris Torek, Lawrence Berkeley Lab CSE/EE (+1 510 486 5427)
  46. Berkeley, CA        Domain:    torek@ee.lbl.gov
  47.