home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / sys / amiga / programm / 17526 < prev    next >
Encoding:
Text File  |  1992-12-21  |  2.5 KB  |  71 lines

  1. Newsgroups: comp.sys.amiga.programmer
  2. Path: sparky!uunet!spool.mu.edu!agate!stanford.edu!rock!concert!sas!mozart.unx.sas.com!walker
  3. From: walker@twix.unx.sas.com (Doug Walker)
  4. Subject: Re: alleged Bug in SAS/C V6.1? IS NOT A BUG, but...
  5. Originator: walker@twix.unx.sas.com
  6. Sender: news@unx.sas.com (Noter of Newsworthy Events)
  7. Message-ID: <BzGJM3.IB8@unx.sas.com>
  8. Date: Fri, 18 Dec 1992 13:46:51 GMT
  9. Distribution: comp
  10. References: <S37732V.92Dec11104414@lk-hp-12.hut.fi> <Bz3nvr.82D@unx.sas.com> <8f=bT9K00hsBMrjYoD@cs.cmu.edu> <MfAFgcS00hsBMfL35d@cs.cmu.edu>
  11. Nntp-Posting-Host: twix.unx.sas.com
  12. Organization: SAS Institute Inc.
  13. Lines: 56
  14.  
  15.  
  16. In article <MfAFgcS00hsBMfL35d@cs.cmu.edu>, mjw+@cs.cmu.edu (Michael Witbrock) writes:
  17. |> However.
  18. |> ~(unsigned short int)0 [the new case that I'm annoyingly introducing], 
  19. |> is  [unsigned int] 1111 1111 1111 1111B   i.e. a large unsigned number!
  20. |> (but still an int, which won't fit into an unsigned short) and CAN'T be
  21. |> written as -1
  22. |> which the compiler does in its warning. 
  23. |> 
  24. |> So the score of now, I think,  SAS/C 1, detractors [well, not really, but...] 1
  25. |> 
  26. |> michael
  27.  
  28. No, it's now SAS/C 2 opposition 0.
  29.  
  30. ~(unsigned short)0 is the expression.  The type of the expression is signed int.
  31.  
  32. Reread your K&R quote about the ~ operator:  "The default integer promotions 
  33. will be performed" or some such statement is in there.  The default integer 
  34. promotions are:
  35.  
  36.    char           -> int
  37.    unsigned char  -> int
  38.    short          -> int
  39.    unsigned short -> int
  40.    int            -> int
  41.    unsigned int   -> unsigned int
  42.    long           -> long
  43.    unsigned long  -> unsigned long
  44.  
  45. in other words, everything shorter than "int" is promoted to "int",
  46. regardless of whether it was signed or unsigned before the promotion.
  47.  
  48. What you have is ~ applied to an unsigned short.  The unsigned short
  49. gets promoted to int, with value 0.  The ~ is applied, giving the
  50. hex pattern 0xffffffff and the type "int".  0xffffffff as an "int"
  51. is the value -1.
  52.  
  53. There's just no way to get any type shorter than int from the ~
  54. operator.  You have to cast the result of ~, not the operand:
  55.  
  56.   (unsigned short)~0
  57.  
  58. Of course, there is always
  59.  
  60.    0xffff
  61.  
  62. -- 
  63.   *****
  64. =*|_o_o|\\=====Doug Walker, Software Distiller====== BBS: (919)460-7430 =
  65.  *|. o.| ||                                          1200/2400/9600 Dual
  66.   | o  |//     For all you do, this bug's for you!
  67.   ====== 
  68. usenet: walker@unx.sas.com                            bix: djwalker 
  69. Any opinions expressed are mine, not those of SAS Institute, Inc.
  70.  
  71.