Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!caen!spool.mu.edu!agate!ucbvax!ulysses!ulysses.att.com!cjc From: cjc@ulysses.att.com (Chris Calabrese) Newsgroups: comp.lang.c Subject: Re: strcmp Message-ID: <15021@ulysses.att.com> Date: 21 Jun 91 17:42:25 GMT Article-I.D.: ulysses.15021 References: <1991Jun18.153653.1494@zoo.toronto.edu> <14421@dog.ee.lbl.gov> <14498@dog.ee.lbl.gov> <6476.Jun2023.30.3491@kramden.acf.nyu.edu> Sender: netnews@ulysses.att.com Organization: AT&T Bell Laboratories, Murray Hill, NJ Lines: 32 In article <6476.Jun2023.30.3491@kramden.acf.nyu.edu>, brnstnd@kramden.acf.nyu.edu (Dan Bernstein) writes: |> On the other hand, how can sizeof(char) == sizeof(int)? I was under the |> impression that sizeof(char) had to be smaller than sizeof(int). |> Otherwise the getchar() interface explodes. If sizeof(char) < |> sizeof(int) and both are some number of bits, then the unsigned char |> subtraction will fit into int without overflow---provided you write it |> correctly: |> |> return ((int) (unsigned int) *(unsigned char *) --s1) |> - ((int) (unsigned int) *(unsigned char *) s2); |> |> This works, right? |> |> ---Dan ANSI makes the assertions that: CHAR_BIT (num of bits in a char) >= 8 sizeof(char) <= sizeof(short) <= sizeof(ing) <= sizeof(long) a short is at least 16 bits a long is at least 32 bits Strictly speaking, there's no guarantee that sizeof(char) < sizeof(long), though K&R 2 does mention stuff about char's being the right size for holding 1 character of the local character so it certainly could be 16 bits on a machine which has an oriental character set. Conceivably, int could also be the same size. -- Name: Christopher J. Calabrese Brain loaned to: AT&T Bell Laboratories, Murray Hill, NJ att!ulysses!cjc cjc@ulysses.att.com Obligatory Quote: ``pher - gr. vb. to schlep. phospher - to schlep light.philosopher - to schlep thoughts.''