C standard: L prefix and octal/hexadecimal escape sequences <p>I didn't find an explanation in the C standard how do aforementioned escape sequences in wide strings are processed.</p> <p>For example:</p> <pre><code>wchar_t *txt1 = L"\x03A9"; wchar_t *txt2 = L"\xA9\x03"; </code></pre> <p>Are these somehow processed (like prefixing each byte with \x00 byte) or stored in memory exactly the same way as they are declared here?</p> <p>Also, how does L prefix operate according to the standard?</p> <p><strong>EDIT:</strong></p> <p>Let's consider txt2. How it would be stored in memory? \xA9\x00\x03\x00 or \xA9\x03 as it was written? Same goes to \x03A9. Would this be considered as a wide character or as 2 separate bytes which would be made into two wide characters?</p> <p><strong>EDIT2:</strong></p> <p>Standard says:</p> <p>The hexadecimal digits that follow the backslash and the letter x in a hexadecimal escape sequence are taken to be part of the construction of a single character for an integer character constant or of a single wide character for a wide character constant. The numerical value of the hexadecimal integer so formed specifies the value of the desired character or wide character.</p> <p>Now, we have a char literal:</p> <pre><code>wchar_t txt = L'\xFE\xFF'; </code></pre> <p>It consists of 2 hex escape sequences, therefore it should be treated as two wide characters. If these are two wide characters they can't fit into one wchar_t space (yet it compiles in MSVC) and in my case this sequence is treated as the following:</p> <pre><code>wchar_t foo = L'\xFFFE'; </code></pre> <p>which is the only hex escape sequence and therefore the only wide char.</p> <p><strong>EDIT3:</strong></p> <p>Conclusions: each oct/hex sequence is treated as a separate value ( wchar_t *txt2 = L"\xA9\x03"; consists of 3 elements). wchar_t txt = L'\xFE\xFF'; is not portable - implementation defined feature, one should use wchar_t txt = L'\xFFFE';</p>