Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!snorkelwacker!apple!agate!violet.berkeley.edu!lindahl From: lindahl@violet.berkeley.edu (Ken Lindahl 642-0866) Newsgroups: comp.unix.aix Subject: Re: Bogus warning from AIX XL C Compiler/6000? Keywords: correct under ANSI definition Message-ID: <1990Aug24.234147.9710@agate.berkeley.edu> Date: 24 Aug 90 23:41:47 GMT References: <1990Aug23.034343.11444@murdoch.acc.Virginia.EDU> <3239@awdprime.UUCP> Sender: usenet@agate.berkeley.edu (USENET Administrator;;;;ZU44) Reply-To: lindahl@violet.berkeley.edu (Ken Lindahl 642-0866) Organization: University of California, Berkeley Lines: 49 In article <3239@awdprime.UUCP> @cs.utexas.edu:ibmchs!auschs!woan.austin.ibm.com!ron writes: >In article <1990Aug23.034343.11444@murdoch.acc.Virginia.EDU>, >mms7r@krebs.acc.Virginia.EDU (Mitch Smith) writes: >Mitch> Problem: The character constant in the following short program >Mitch> produces a bogus warning. >Mitch> /* test1.c */ main() { int c; >Mitch> c = '\x'; printf("c = %c\n", c); exit(0); } >Mitch> ..............a.. a - 1506-235: (W) Illegal escape sequence x >Mitch> ignored. $ > >Mitch> In fact, 'x' is not ignored. When executed, the >Mitch> compiled program prints "c = x". > [text deleted] > >Yes, get the new ANSI edition of K&R. On page 193: "If the character >following the \ is not one of those specified, the behavior is >undefined." And actually, 'x' just happens to have been defined for >specifying constants in hex, i.e. '\x07' is the bell. You should thank >your lucky stars that you got the right output or the fact that IBM >has tried to be as backwards compatible as possible, so they only gave >you a very good warning message with an indication of what it was >going to do with it. Anyway, this doesn't seem like something you >should be trying to do anyway, afterall what's wrong with c='x'? > Nit: I think a "very good warning message" should be more accurate, e.g.: (W) Undefined escape sequence '\x'. Replaced by 'x'. More importantly, this and an earlier posting referred to the '\xNN' escape sequence, where NN is a hex number indexing the ASCII character set. It seems to me that this should only apply to the situation where the '\x' is followed by at least one character from the set [0123456789ABCDEF]. That is, '\x' should be treated like any other undefined, non-hex escape sequence. (Note this is exactly what the compiler has done. I'm not taking issue with the compiler, but with the two postings.) If you try to interpret '\x' as a hex escape, the only reasonable (?) interpretation is '\x00' and the compiler should insert a NUL character. This is not a recommendation on my part. This probably ought to go to comp.lang.c.dementia, but I don't subscribe to that newsgroup. Ken Lindahl lindahl@violet.berkeley.edu Advanced Technology Planning, Information Systems and Technology University of California at Berkeley P.S. to Mitch: You really should have recognized the problem as soon as you saw the error number, "1506-235". :-)