Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.milw.wisc.edu!lll-winken!uunet!mcvax!ukc!stl!datlog!scm From: scm@datlog.co.uk ( Steve Mawer ) Newsgroups: comp.lang.c Subject: Re: type of character constants Keywords: character constants Message-ID: <1813@dlvax2.datlog.co.uk> Date: 15 Mar 89 08:08:00 GMT References: <13068@steinmetz.ge.com> <102@servio.UUCP> <10138@socslgw.csl.sony.JUNET> <1783@dlvax2.datlog.co.uk> <3711@xyzzy.UUCP> <1644@vicorp.UUCP> <766@twwells.uucp> Reply-To: scm@datlog.co.uk ( Steve Mawer ) Organization: Data Logic Ltd, Queens House, Greenhill Way, Harrow, London. Lines: 33 First let me start by apologising for the content of my misguided contribution to the character constant type/size debate. I had always interpreted the meaning of character constant as 'constant of type char(acter)' and have used expressions of the form 'x' whenever I've need to define characters. In a lot of other code I've seen (not influenced by me!) others appear to share my (incorrect) assumptions. Thanks to the responses I've received, I believe I now fully understand the concept of character constants. Where I've been bitten in the past is when I've used them to define 8 bit characters (e.g. for PC code sets) and have found that few compilers I've used believe e.g. (0200 == '\200'). I'd always thought this was due to the 8 bit value '\200' being widened to an int for the comparison and having (optional) sign extension done. However, many compilers didn't even believe (0200 == (unsigned)'\200'). I now realise this must be due to the \200 being the 8 bit value and the inclusion of the surrounding quotes causing the widening, leaving the value (optionally) sign extended at that time. That's cleared that up (or so I thought). But then .. in article <766@twwells.uucp> bill@twwells.UUCP (T. William Wells) writes: > >There is a subtle difference. If 'c' is an integer constant, '\377' >represents the value 255. If, on the other hand, it is a char >constant, and characters sign extend, it represents -1. > As noted above, most compilers I've used believe that '\377' *is* -1; in fact the only one I can recall that makes it 255 is that supplied with AIX. So what is the 'correct' value for '\377', 255 or -1? -- Steve C. Mawer or < {backbone}!ukc!datlog!scm > Voice: +44 1 863 0383 (x2153)