Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Separating hexadecimal escape sequences in strings

Tags:

c

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

like image 354
August Karlstrom Avatar asked Nov 30 '17 10:11

August Karlstrom


2 Answers

"foo" "\x01" "bar" is a string literal.

The C standard states that a hexadecimal escape sequence is the longest sequence of characters that can constitute the escape sequence. Without the explicit concatenation (which is the common workaround to this problem), the compiler parses \x01ba which is obviously out of range.

like image 91
Bathsheba Avatar answered Oct 13 '22 01:10

Bathsheba


How about "foo\x01\142ar"? Is that cheating?

like image 22
unwind Avatar answered Oct 13 '22 00:10

unwind