| glen herrmannsfeldt 2007-11-24, 7:10 pm |
| James Van Buskirk wrote:
(snip)
> Well, not quite. Having high priority is normally undesirable I
> think, but of course we could always use parentheses. Let's see...
> we have to change '\a' to achar(7), '\b' to achar(8), '\f' to achar(12),
> '\n' to achar(10), '\r' to achar(13), '\t' to achar(9), '\v' to achar(11),
> "'" to achar(39), '\"' to achar(34), '\' to achar(92), '\?' to achar(63)
> and all that, but also '\1' to achar(1), '\12' to achar(10) and
> '\123' to achar(83). Also, achar(92)//achar(10) translates to ''.
> Microsoft says that '\c' should translate to 'c' but gfortran would
> translate it to '\c'.
K&R2, and I believe C89, leave these undefined. Many C compilers
generate them as 'c'.
> http://msdn2.microsoft.com/en-us/library/h21280bw(VS.80).aspx
> Translate '\x12' obviously to achar(18), but does that mean
> '\x1' becomes achar(1)? How about '\x123' or '\x'? These seem
> to not be unambiguously defined.
Most that I know of allow one, two, or three octal digits and
two hex digits. K&R2 says "There is no limit on the number of
digits, but the behavior is undefined if the resulting character
value exceeds that of the largest character." (This could be
interesting on systems with char larger than eight bits.)
--------------------------------
I suppose I don't see anything wrong with doing it as a function,
though I have never seen that done in C. In C, they are by
definition done to character constants allowing one to put
in characters that would otherwise be difficult.
As a side note, Java has unicode escapes of the form \uXXXX
where XXXX is four hex digits. These escapes are processed
earlier than string escapes, such that a line like:
s="some string\u000a";
will fail with an unterminated string, though
s="another string\u0022;
will work fine.
(snip)
> Even C compilers implement these escape sequences differently.
How are they different? The single character escapes should work
the same on all systems. The octal and hex escapes, if followed
by an octal or hex digit, could be done differently I suppose.
> Therefore anyone who uses them in C has to be ready to change
> his escape sequences around as the program is ported to different
> compilers. Changing them to invocations of ACHAR is then just
> as normal as would be the case in changing C compilers.
Do you have any examples that were done differently?
-- glen
|