Hexadecimal Escape Sequence

Henry Spencer henry at utzoo.uucp
Wed Jan 17 06:45:56 AEST 1990


In article <11960 at smoke.BRL.MIL> gwyn at brl.arpa (Doug Gwyn) writes:
>... Two hex digits is not always enough.

Admittedly a problem...

>>After all, the octal escape sequence limits itself to 3 characters...
>That's a deficiency in the octal escape sequence design that we were
>able to remedy for the newly invented hex sequences.

Introducing, in return, a new deficiency:  the inability to terminate
the hex sequence simply and cleanly when desired.  Don't think this
wasn't pointed out during the public reviews, by me among others.
Among other things, it is a violation of the "prior art" rule, since
prior experience (C++ and some C compilers) has been entirely (I think)
with limited-length versions.

>>If it IS correct, how do you write "<ESC>fred" using a hex escape?
>The simplest method is to use string concatenation:
>	printf("\x1b""fred");

As the man said, "there's *got* to be a better way".  Unfortunately, none
made it into the standard.  Using string concatenation for this is an
ugly kludge, not a proper solution.  The right way would have been to
include some sort of bracketing as part of the escape, e.g. "\x(ab)".
This would even have allowed compatibility with C++ and other prior art:
length is unlimited only within brackets, with plain "\xabc" being limited
to three digits like the octal escapes.

Alas, it's too late now.  I expect the result will be widespread aversion
to the error-prone context-sensitive hex escapes, defeating the original
purpose of making life easier.
-- 
1972: Saturn V #15 flight-ready|     Henry Spencer at U of Toronto Zoology
1990: birds nesting in engines | uunet!attcan!utzoo!henry henry at zoo.toronto.edu



More information about the Comp.std.c mailing list