Hexadecimal Escape Sequence

Steve Hosgood iiitsh at cybaswan.UUCP
Mon Jan 15 22:32:03 AEST 1990


I recently discovered in K&R Edition 2 (ANSII C) that the hex escape
sequence will accept any number of valid hex characters after the "\x".
This means that the printf statement:-

	printf("\x1bfred");	/* i.e "<ESC>fred" */

..suddenly failed in a program when we updated from Microsoft 4.0 to
5.1 recently.

According to K&R2, (my only reference), MSC5.1 interprets this correctly
as "<hex BF>red", and 4.0 was wrong to limit itself to 2 hex chars following
the \x. It seems that an infinite number of hex characters may follow the
\x sequence, though what happens if the result fails to fit in a char is
undefined.

Is this what you'd call "expected behaviour"?

After all, the octal escape sequence limits itself to 3 characters...

If it IS correct, how do you write "<ESC>fred" using a hex escape? I
ended up having to use the octal escape in the end, which seems rather
an inelegant method.

Thanks in advance for any insights.
Steve 



More information about the Comp.std.c mailing list