title: When did C++ compilers start considering more than two hex digits in string literal character escapes?
body: <p>I've got a (generated) literal string in C++ that may contain characters that need to be escaped using the <code>\x</code> notation. For example:</p>
  
  <pre><code>char foo[] = "\xABEcho";
  </code></pre>
  
  <p>However, g++ (version 4.1.2 if it matters) throws an error:</p>
  
  <pre><code>test.cpp:1: error: hex escape sequence out of range
  </code></pre>
  
  <p>The compiler appears to be considering the <code>Ec</code> characters as part of the preceding hex number (because they look like hex digits). Since a four digit hex number won't fit in a <code>char</code>, an error is raised. Obviously for a wide string literal <code>L"\xABEcho"</code> the first character would be U+ABEC, followed by <code>L"ho"</code>.</p>
  
  <p>It seems this has changed sometime in the past couple of decades and I never noticed. I'm almost certain that old C compilers would only consider <em>two</em> hex digits after <code>\x</code>, and not look any further.</p>
  
  <p>I can think of one workaround for this:</p>
  
  <pre><code>char foo[] = "\xAB""Echo";
  </code></pre>
  
  <p>but that's a bit ugly. So I have three questions:</p>
  
  <ul>
  <li><p>When did this change?</p></li>
  <li><p>Why doesn't the compiler only accept >2-digit hex escapes for wide string literals?</p></li>
  <li><p>Is there a workaround that's less awkward than the above?</p></li>
  </ul>