home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!charon.amdahl.com!pacbell.com!decwrl!sdd.hp.com!cs.utexas.edu!zaphod.mps.ohio-state.edu!uunet.ca!wildcan!sq!msb
- From: msb@sq.sq.com (Mark Brader)
- Subject: Re: Help. (Unix C)
- Message-ID: <1992Nov6.055934.18694@sq.sq.com>
- Supersedes: <1992Nov6.035051.16838@sq.sq.com>
- Organization: SoftQuad Inc., Toronto, Canada
- References: <1992Nov5.154636.10510@pica.army.mil> <1992Nov5.162818.10918@pica.army.mil>
- Date: Fri, 6 Nov 92 05:59:34 GMT
- Lines: 25
-
- [Corrected version; apologies if you already read the now-cancelled original.]
-
- > > you could do simply
- > >
- > > return (ptr->item1 - ptr->item2);
-
- > This works for intgers, not floats (sorry)
-
- No, this works only for types that are (a) *narrower* than int, and
- (b) signed. Therefore it should not be used for this application!
-
- If item1 and item2 are 16-bit ints, try it on the case where their
- respective values are 20000 and -20000. If they are 32-bit ints,
- append 00000 to each of these, and then try it. If you are lucky,
- you are on an implementation that detects arithmetic overflow and
- your program terminates. More likely the comparison just returns
- the wrong result.
-
- Verbose as it may seem to some, the approach of doing two separate
- comparisons really is the only safe one.
- --
- Mark Brader, SoftQuad Inc., "Verbose better."
- Toronto, utzoo!sq!msb, msb@sq.com -- David M. Sherman
-
- This article is in the public domain.
-