Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!think!harvard!seismo!mcvax!ukc!warwick!jeff From: jeff@warwick.UUCP (Jeff Smith) Newsgroups: net.lang.c++,net.lang.c Subject: octal character constants Message-ID: <252@ubu.warwick.UUCP> Date: Thu, 10-Apr-86 07:59:25 EST Article-I.D.: ubu.252 Posted: Thu Apr 10 07:59:25 1986 Date-Received: Sat, 12-Apr-86 22:22:40 EST Distribution: net Organization: Computer Science, Warwick University, UK Lines: 63 Xref: watmath net.lang.c++:155 net.lang.c:8532 There is a comment in the C++ Release 1 translator sizeof("\01") a syntax error (c_strlen in size.c) The relevant part of K+R says: `The escape \ddd consists of the backslash followed by 1, 2, or 3 octal digits which are taken to specify the value of the desired character. A special case of this construction is \0 (not followed by a digit), which indicates the character NUL.' (p181) Bjarne's manual says the same. (p246) I claim that the string "p\01q" is legal, has four characters in it (p, SOH, q and NUL) and will be passed through as is by cfront (whereas \xddd (c++ hex feature) constructs will always generate escape sequences with the full three digits). In which case c_strlen should be replaced by the following code: #ifdef OCTALDDDFIX #include static inline isoctal(char c) { return (isascii(c) && isdigit(c) && c != '9' && c != '8'); } int c_strlen(char* s) { int i = 1; for (register char* p = s; *p; i++,p++) if (*p == '\\') { if (isoctal(*++p)) { if (! isoctal(*++p)) p--; else if (! isoctal(*++p)) p--; } } return i; } #else !OCTALDDDFIX int c_strlen(char* s) /* return sizeof(s) with escapes processed sizeof("") == 1 the terminating 0 sizeof("a") == 2 sizeof("\0x") == 3 0 x 0 sizeof("\012") == 2 '\012' sizeof("\01") a syntax error sizeof("\x") == 2 \ ignored */ { /* old body, not quoted here lest the ghost of Old Ma Bell haunt me forever */ } #endif OCTALDDDFIX Or maybe Bjarne intended the chconst code in lex.c to translate all character constants to three-digit form. Bjarne? -------------------------------------- ...mcvax!warwick!jeff (uucp) ..jeff%warwick.uucp@ucl-cs.arpa (arpa)