This compiles without warning in clang and gcc:
const char *foo = "\%";
The resulting string is the same as "%"
.
What is this escape for? Where can I find a complete list of escapes?
I thought maybe it was for escaping digraphs, but other digraph characters produce warnings (e.g. "\:"
).
Thanks for any help!
Answering my own question: it's to support SCCS, which is a 40-year old revision control system, that predates even RCS. Ha!
Digging into the compilers, clang supports this because it thinks gcc does:
case '(': case '{': case '[': case '%':
// GCC accepts these as extensions. We warn about them as such though.
Lies! The warnings show up, but only with the -pedantic
flag (in both compilers).
Oh, and gcc? It supports the first three for emacs, which I guess is easily confused:
/* `\(', etc, are used at beginning of line to avoid confusing Emacs. */
case '(':
case '{':
case '[':
but the last one:
/* `\%' is used to prevent SCCS from getting confused. */
case '%':
if (pedantic)
pedwarn ("non-ANSI escape sequence `\\%c'", c);
return c;
SCCS support! It's glorious!
According to the C standard, any escape sequence not mentioned by the Standard is a syntax error.
This means that the compiler must produce a diagnostic, but the compiler could define an extension (e.g. ignore the \
) and continue compiling the rest of the program.
The standard escape sequences are: \' \" \? \\ \a \b \f \n \r \t \v
, and also the octal, hex and universal character constants introduces by \
(digit), \x
and \u
respectively.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With