Summary: | Hex constant characters with \x escape not parsing correctly | ||
---|---|---|---|
Product: | gcc | Reporter: | Weston Hopkins <weston> |
Component: | c | Assignee: | Not yet assigned to anyone <unassigned> |
Status: | RESOLVED INVALID | ||
Severity: | minor | CC: | gcc-bugs, weston |
Priority: | P3 | ||
Version: | 4.1.0 | ||
Target Milestone: | --- | ||
Host: | i586-suse-linux | Target: | i586-suse-linux |
Build: | i586-suse-linux | Known to work: | |
Known to fail: | Last reconfirmed: |
Description
Weston Hopkins
2007-08-23 21:49:33 UTC
No GCC is correct. The standard says: Each octal or hexadecimal escape sequence is the longest sequence of characters that can constitute the escape sequence. So that means the B is going to be taken and be used for the hexadecimal escape sequence. Yep, looks like you are right from the standard. That sucks then. I wish it were the other way because I don't see a way to enter a literal single character in hex followed a by single character [A-Z0-9] without escape sequences. Thanks for the quick response. (In reply to comment #2) > Yep, looks like you are right from the standard. That sucks then. I wish it > were the other way because I don't see a way to enter a literal single > character in hex followed a by single character [A-Z0-9] without escape > sequences. char *string = "\x01\x02\x03" "Bob"; should work. if gcc hex escapes is right, then gcc octal escape is wrong (it just look at first 3 octals) "\123" = "S" "\0123" = "\n3" ?? "\00123" = "\1" "23" ?? personally, i like this octal escape "bug" The standard syntax production for octal-escape-sequence (C11 6.4.4.4#1) only allows one, two or three digits. if gcc hex escape AND octal is right, does it contradict comment #1 ? "octal or hexadecimal ... longest sequence that constitute escape sequence" I noticed OLD python (2.0) also use the C rule regarding hex escapes, but later switch to a more sensible 2 hex = 1 byte rule (\xX or \xXX) "longest sequence of characters that can constitute the escape sequence" resolves an ambiguity between alternative parses permitted by the syntax; it doesn't need to deal with anything that is not permitted by the syntax. Four or more octal characters in an octal sequence are not a parse permitted by the syntax, whereas more than two hex characters in a hex sequence are a parse permitted by the syntax. |