Separating hexadecimal escape sequences in strings

Can a string like constant "foo" "\x01" "bar"be written as a single string literal (preserving the hexadecimal notation)? With the "foo\x01bar"escape sequence, it seems to be interpreted as \x01ba, since I get the warning “hex escape sequence out of range”.

+6
source share
3 answers

"foo" "\x01" "bar" - string literal.

The C standard states that a hexadecimal escape sequence is the longest sequence of characters that can make up an escape sequence. Without explicit concatenation (which is a workaround for this problem), the compiler parses \x01ba, which is clearly out of range.

+3
source

How about "foo\x01\142ar"? This is a fraud?

+1
source

Another solution is to simply write the escape character in octal rather than hexadecimal

"foo\1bar"

and no more ambiguity ...

+1
source

All Articles