> From: Tim [mailto:[EMAIL PROTECTED]]
> I'm using CW R6 [...] and I can't get consistent results embedding
> escape characters into string constants.  It appears to me to be a 
> compiler problem

No, the compiler is following the language standard correctly here.

> This doesn't work: "so\xF1ar", (s, o, n tilde, a, r).
> The compiler gives the following error:
> Error   : illegal character constant
> The error message is produced whenever the following character is <= 'f'.

Right.  According to the standard, a hex literal isn't just 2 characters (as
you intend) but is actually any number of legal hex characters following the
"\x" until the first non-hex character.  So your literal is being seen as
"\xF1a" which is in fact not a legal 8-bit character.

> Any suggestions?

1. Use octal: "so\361ar".  With octal you should always use the full 3
digits so prevent this sort of problem.  Octal constants are limited to a
maximum of 3 digits so even if the following character happened to be a
legal octal digit, the compiler wouldn't treat it as one.

2. You can use hex by breaking up the string: "so\xF1" "ar".  Putting two
string literals next to each other like this is equivalent to writing it as
one long string, but in this particular case the first quotation mark also
serves to terminate the "\xF1" literal.

(Actually I'm not sure if #2 is the standard defined behavior, but at least
it works in the Metrowerks compiler.  My Stroustrup book doesn't say.)

-slj-


-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/tech/support/forums/

Reply via email to