strcmp

Chris Calabrese cjc at ulysses.att.com
Sat Jun 22 03:42:25 AEST 1991


In article <6476.Jun2023.30.3491 at kramden.acf.nyu.edu>, brnstnd at 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 at ulysses.att.com
Obligatory Quote:	``pher - gr. vb. to schlep.  phospher - to schlep light.philosopher - to schlep thoughts.''



More information about the Comp.lang.c mailing list