What is a backslash escape in C?

This compiles without warning in clang and gcc:

const char *foo = "\%";

The resulting string is the same as "%".

What is it for? Where can I find a complete list of screens?

I thought it might have been to elude the digraphs, but other digraph symbols generate warnings (for example, "\:").

Thanks for any help!

+4
source share
2 answers

Answering my own question: it supports SCCS, which is a 40-year version of the version control system that even precedes RCS. Ha!

Delving into compilers, clang supports this because it thinks gcc is doing :

case '(': case '{': case '[': case '%':
// GCC accepts these as extensions.  We warn about them as such though.

! , -pedantic ( ).

, gcc? emacs, , , :

/* `\(', etc, are used at beginning of line to avoid confusing Emacs.  */
case '(':
case '{':
case '[':

:

  /* `\%' is used to prevent SCCS from getting confused.  */
case '%':
  if (pedantic)
      pedwarn ("non-ANSI escape sequence `\\%c'", c);
  return c;

SCCS! !

+6

C escape-, , .

, , (, \) .

escape-: \' \" \? \\ \a \b \f \n \r \t \v, , \ (), \x \u .

+1

Source: https://habr.com/ru/post/1618943/


All Articles