🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #1074

Hexadecimal Escape Sequence

#1074
From: Steve Hosgood
Date: Mon, 15 Jan 1990 11:32
25 lines
1422 bytes
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 
Technical Details
Message-ID: <1335@cybaswan.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!uunet!mcsun!ukc!reading!cf-cm!cybaswan!iiitsh

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!uunet!mcsun!ukc!reading!cf-cm!cybaswan!iiitsh
From: iiitsh@cybaswan.UUCP (Steve Hosgood)
Newsgroups: comp.std.c
Subject: Hexadecimal Escape Sequence
Summary: "\xabcdef" is a valid escape seq. Is this right?
Message-ID: <1335@cybaswan.UUCP>
Date: 15 Jan 90 11:32:03 GMT
Reply-To: iiitsh@cybaswan.UUCP (Steve Hosgood)
Organization: Institute for Industrial Information Technology
Lines: 25