home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sys.amiga.programmer
- Path: sparky!uunet!spool.mu.edu!agate!stanford.edu!rock!concert!sas!mozart.unx.sas.com!walker
- From: walker@twix.unx.sas.com (Doug Walker)
- Subject: Re: alleged Bug in SAS/C V6.1? IS NOT A BUG, but...
- Originator: walker@twix.unx.sas.com
- Sender: news@unx.sas.com (Noter of Newsworthy Events)
- Message-ID: <BzGJM3.IB8@unx.sas.com>
- Date: Fri, 18 Dec 1992 13:46:51 GMT
- Distribution: comp
- References: <S37732V.92Dec11104414@lk-hp-12.hut.fi> <Bz3nvr.82D@unx.sas.com> <8f=bT9K00hsBMrjYoD@cs.cmu.edu> <MfAFgcS00hsBMfL35d@cs.cmu.edu>
- Nntp-Posting-Host: twix.unx.sas.com
- Organization: SAS Institute Inc.
- Lines: 56
-
-
- In article <MfAFgcS00hsBMfL35d@cs.cmu.edu>, mjw+@cs.cmu.edu (Michael Witbrock) writes:
- |> However.
- |> ~(unsigned short int)0 [the new case that I'm annoyingly introducing],
- |> is [unsigned int] 1111 1111 1111 1111B i.e. a large unsigned number!
- |> (but still an int, which won't fit into an unsigned short) and CAN'T be
- |> written as -1
- |> which the compiler does in its warning.
- |>
- |> So the score of now, I think, SAS/C 1, detractors [well, not really, but...] 1
- |>
- |> michael
-
- No, it's now SAS/C 2 opposition 0.
-
- ~(unsigned short)0 is the expression. The type of the expression is signed int.
-
- Reread your K&R quote about the ~ operator: "The default integer promotions
- will be performed" or some such statement is in there. The default integer
- promotions are:
-
- char -> int
- unsigned char -> int
- short -> int
- unsigned short -> int
- int -> int
- unsigned int -> unsigned int
- long -> long
- unsigned long -> unsigned long
-
- in other words, everything shorter than "int" is promoted to "int",
- regardless of whether it was signed or unsigned before the promotion.
-
- What you have is ~ applied to an unsigned short. The unsigned short
- gets promoted to int, with value 0. The ~ is applied, giving the
- hex pattern 0xffffffff and the type "int". 0xffffffff as an "int"
- is the value -1.
-
- There's just no way to get any type shorter than int from the ~
- operator. You have to cast the result of ~, not the operand:
-
- (unsigned short)~0
-
- Of course, there is always
-
- 0xffff
-
- --
- *****
- =*|_o_o|\\=====Doug Walker, Software Distiller====== BBS: (919)460-7430 =
- *|. o.| || 1200/2400/9600 Dual
- | o |// For all you do, this bug's for you!
- ======
- usenet: walker@unx.sas.com bix: djwalker
- Any opinions expressed are mine, not those of SAS Institute, Inc.
-
-