I just had a quick look at the ANSI standard for escaped character constants to see
what is in the latest standard.
I came away with a new understanding of the standard requirements
(which I think is different from how it worked years ago) and a
feeling that it is kind of a bummer the way it is defined since
it can create potential unexpected issues based on peoples assumptions
of how it works vs how it really works.
The ANSI standard defines these types of constants as:Each octal or hexadecimal escape sequence is the longest sequence of characters
that can constitute the escape sequence.
So that can create unexpected issues depending on what follows next.
i.e. trying to print the degree symbol followed by 'C'.
Would be a problem since the C is a valid hex character.
the hex constant becomes 0xdfc which is too large and then either generates
an error or a warning. If a warning you get the single value 0xfc instead of degree symbol and 'C'.
Same is true for Octal.
While octal has the same issue, it gets "lucky" more often than hex
since octal only uses the numbers 0 to 7.
"\337C" would work as C is not a valid octal character.
Consider this example:
Suppose custom character 1 was an upside-down exclamation
and you wanted a phrase to start with that:
"\00142 is the answer!"
The constant again becomes too large as the compiler interprets
00142 as the value instead of just 001.
It means that you should always use multiple strings and let the compiler
combine them to avoid any potential issues.
"\001" "42 is the answer!"
So the safest way to handle escaped constants embedded in a string with other characters
is to always isolate the escaped constants inside their own quotes.
lcd.print("\010" "EPMOKPA" "\001" "IA:");
lcd.print("\x08" "EPMOKPA" "\x01" "IA:");
lcd.print("\xf2" "EPMOKPA" "\xf6" "IA:"); // use theta an sigma from LCD character set