3 ms·
I wondered if clang has the same property, but it's explicitly coded as 10 (in lib/Lex/LiteralSupport.cpp): /// ProcessCharEscape - Parse a standard C esca
by titwank 2y ago
I wondered if clang has the same property, but it's explicitly coded as 10 (in lib/Lex/LiteralSupport.cpp):
/// ProcessCharEscape - Parse a standard C escape sequence, which can occur in
/// either a character or a string literal.
static unsigned ProcessCharEscape(const char *ThisTokBegin,
const char *&ThisTokBuf,
const char *ThisTokEnd, bool &HadError,
FullSourceLoc Loc, unsigned CharWidth,
DiagnosticsEngine *Diags,
const LangOptions &Features) {
const char *EscapeBegin = ThisTokBuf;
// Skip the '\' char.
++ThisTokBuf;
// We know that this character can't be off the end of the buffer, because
// that would have been \", which would not have been the end of string.
unsigned ResultChar = *ThisTokBuf++;
switch (ResultChar) {
...
case 'n':
ResultChar = 10;
break;
...
- titwank 2y agoSimilarly in GCC it is hardcoded, with a choice of ASCII or EBCDIC (in gcc/libcpp/charset.cc): /* Convert an escape sequence (pointed to by FROM) to its value on the target, and to the execution character set. Do not scan past LIMIT. Write the converted value into TBUF, if TBUF is non-NULL. Returns an advanced pointer. Handles all relevant diagnostics. If LOC_READER is non-NULL, then RANGES must be non-NULL: location information is read from *LOC_READER, and *RANGES is updated accordingly. */ static const uchar * convert_escape (cpp_reader *pfile, const uchar *from, const uchar *limit, struct _cpp_strbuf *tbuf, struct cset_converter cvt, cpp_string_location_reader *loc_reader, cpp_substring_ranges *ranges, bool uneval) { /\* Values of \a \b \e \f \n \r \t \v respectively. */ #if HOST_CHARSET == HOST_CHARSET_ASCII static const uchar charconsts[] = { 7, 8, 27, 12, 10, 13, 9, 11 }; #elif HOST_CHARSET == HOST_CHARSET_EBCDIC static const uchar charconsts[] = { 47, 22, 39, 12, 21, 13, 5, 11 }; #else #error "unknown host character set" #endif uchar c; /* Record the location of the backslash. */ source_range char_range; if (loc_reader) char_range = loc_reader->get_next (); c = *from; switch (c) { ... case 'n': c = charconsts[4]; break; ...
- johnisgood 2y agoIf so, this should answer the question where the compiler knows it from?