Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!thunder.mcrcim.mcgill.edu!snorkelwacker.mit.edu!usc!sdd.hp.com!think.com!compass!worley From: worley@compass.com (Dale Worley) Newsgroups: comp.lang.c Subject: Re: 0xFF != '\xFF' ? Message-ID: Date: 8 May 91 14:03:02 GMT References: <3907@inews.intel.com> Sender: root@compass.com Organization: Compass, Inc., Wakefield, MA, U.S.A. Lines: 32 In-reply-to: wolfram@cip-s01.informatik.rwth-aachen.de's message of 8 May 91 11:19:23 GMT In article wolfram@cip-s01.informatik.rwth-aachen.de (Wolfram Roesler) writes: Subject: Re: 0xFF != '\xFF' ? BTW, isnt a char defined to contain at least 8 bits in Ansi-C? I read something about that in a (however rather unprecise) book. Yes, chars are required to have at least 8 bits. See section 2.2.4.2 of the standard. However beware that "character constants" in C really have type int. The standard states: "If [a] character constant contains a single character or escape sequence, its value is the one that results when an object with type char whose value is that of the single character or escape sequence is converted to type int." (3.1.3.4, page 30, line 33, Dec 88 draft) This means that if your chars are *signed*, character constants with the high bit on will be *sign-extended* into ints. If you want to avoid this, you will probably have to say (unsigned char)'\xFF' Then the conversion to int is done by zero-extending rather than sign-extending. In general, signed char's are losing, especially if you have characters with values >127. Dale Dale Worley Compass, Inc. worley@compass.com -- You have joined the Legion to die. We will send you where you can die. -- Plaque reputedly posted in mess halls of the French Foreign Legion.