[comp.lang.c] Value of x?

ASC::GUTHERY%slb-test.csnet@relay.cs.net (03/31/87)

C Guri:
In the Microsoft C compiler V4.0, '\x' is compiled as 0 on the
grounds that it's a brain-damaged version of '\x00'.  This is what
Microsoft's support group said when I reported what I thought was a 
bug.  I claim that '\x' is a perfectly fine representation of the 
character x and should have value 120 base 10.  How sayeth INFO-C?

gwyn@brl-smoke.UUCP (03/31/87)

In article <6570@brl-adm.ARPA> @relay.cs.net> writes:
>C Guri:
>In the Microsoft C compiler V4.0, '\x' is compiled as 0 on the
>grounds that it's a brain-damaged version of '\x00'.  This is what
>Microsoft's support group said when I reported what I thought was a 
>bug.  I claim that '\x' is a perfectly fine representation of the 
>character x and should have value 120 base 10.  How sayeth INFO-C?

Future ANSI-conforming C compilers will treat '\xNNN' (where NNN are
1 to 3 hexadecimal digits) as the hex code for a character.  '\x'
is not supposed to be a valid hex code, but we don't say what it is;
definitely it's not guaranteed to be just the letter 'x'.

By the way, I intend to submit an improved proposal for removing the
limit to the number of bits supported for \x.  The one I presented
at the very end of the last meeting ran into at least one valid
objection (I had also proposed extending the \0 constants, which can
cause problems with existing code that uses embedded NULs).

So, basically, MicroSoft is right, except it would be nicer if they
would diagnose the case of missing NNN after the \x.

ron@brl-sem.UUCP (04/01/87)

In article <6570@brl-adm.ARPA>, @relay.cs.net> writes:

> In the Microsoft C compiler V4.0, '\x' is compiled as 0 on the
> grounds that it's a brain-damaged version of '\x00'.  This is what
> Microsoft's support group said when I reported what I thought was a 
> bug.  I claim that '\x' is a perfectly fine representation of the 
> character x and should have value 120 base 10.  How sayeth INFO-C?

Neither \x meaning 0 nor \x meaning 'x' is correct.  There is no meaning
to \x and those who use it are asking for trouble.  By your own admission
\n should be the character n which we all know is not true.

dlnash@ut-ngp.UUCP (04/01/87)

In article <705@brl-sem.ARPA>, ron@brl-sem.ARPA (Ron Natalie <ron>) writes:
> In article <6570@brl-adm.ARPA>, @relay.cs.net> writes:
> 
> > In the Microsoft C compiler V4.0, '\x' is compiled as 0 on the
> > grounds that it's a brain-damaged version of '\x00'.  This is what
> > Microsoft's support group said when I reported what I thought was a 
> > bug.  I claim that '\x' is a perfectly fine representation of the 
> > character x and should have value 120 base 10.  How sayeth INFO-C?
> 
> Neither \x meaning 0 nor \x meaning 'x' is correct.  There is no meaning
> to \x and those who use it are asking for trouble.  By your own admission
> \n should be the character n which we all know is not true.


K&R p.181:  "If the character following a backslash is not one of those
            specified [the specified characters are n, t, b, r, f, \, ',
            and ddd (three octal digits) -ed.], the backslash is ignored."


				Don Nash

UUCP:    ...!{ihnp4, allegra, seismo!ut-sally}!ut-ngp!dlnash
ARPA:    dlnash@ngp.UTEXAS.EDU
BITNET:	 CCEU001@UTADNX, DLNASH@UTADNX
TEXNET:  UTADNX::CCEU001, UTADNX::DLNASH

law@qtc.UUCP (04/01/87)

In article <6570@brl-adm.ARPA> @relay.cs.net> writes:
>bug.  I claim that '\x' is a perfectly fine representation of the 
>character x and should have value 120 base 10.  How sayeth INFO-C?

Kernighan and Ritchie, pg 181:

    If the character following a backslash is not one of those specified
    [in the table of valid escape sequences], the backslash is ignored.
                                              ^^^^^^^^^^^^^^^^^^^^^^^^

No more authoritative source exists on the planet (8-).

    


-- 
"A man hears what he wants to hear and disregards the rest"

Larry Westerman  Quantitative Technology Corporation  Beaverton OR 503-626-3081
   ...verdix! or ...sequent! qtc!law

amos@instable.UUCP (04/01/87)

According to K&R (p. 180), if the character following \ is not
one of the special escape sequences, the \ is ignored.
H&S's new C Manual (P.20-22) define a character constant's escape
sequence as \ followed by one of: b t n v f r ' "  Anything else
does not constitute a valid escape sequence and should be, therefore,
illegal (or at least undefined).
-- 
	Amos Shapir
National Semiconductor (Israel)
6 Maskit st. P.O.B. 3007, Herzlia 46104, Israel  Tel. (972)52-522261
amos%nsta@nsc.com {hplabs,pyramid,sun,decwrl} 34.48'E 32.10'N

djfiander@watnot.UUCP (04/01/87)

>> In the Microsoft C compiler V4.0, '\x' is compiled as 0 on the
>> grounds that it's a brain-damaged version of '\x00'.  This is what
>> Microsoft's support group said when I reported what I thought was a 
>> bug.  I claim that '\x' is a perfectly fine representation of the 
>> character x and should have value 120 base 10.  How sayeth INFO-C?
>
>Neither \x meaning 0 nor \x meaning 'x' is correct.  There is no meaning
>to \x and those who use it are asking for trouble.  By your own admission
>\n should be the character n which we all know is not true.

I hate to say this, the first of you is more right.
According to K&R (which admittedly may no longer be correct) if a '\' is
followed by something which is not a valid escape sequence, the '\' is 
ignored, so the first posting has a valid complaint.  This came up here
with one of the University's C compilers.  They changed it to react in the
K&R manner, but give a compile time warning that something was wrong.
I tend to agree that '\x' is an 'x' and not a 0.  If I wanted 0 then I would
say '\x00' (well '\0').

-- 
"I don't want to achieve immortality through my work.
I want to achieve immortality through not dying"
	- Woody Allen

UUCP  : {allegra,ihnp4,decvax,utzoo,clyde}!watmath!watnot!djfiander
CSNET : djfiander%watnot@waterloo.CSNET

drw@cullvax.UUCP (04/02/87)

C Guri:@relay.cs.net> writes:
> In the Microsoft C compiler V4.0, '\x' is compiled as 0 on the
> grounds that it's a brain-damaged version of '\x00'.  This is what
> Microsoft's support group said when I reported what I thought was a 
> bug.  I claim that '\x' is a perfectly fine representation of the 
> character x and should have value 120 base 10.  How sayeth INFO-C?

Well, according to the ANSI draft standard, it's invalid.

Dale
-- 
Dale Worley		Cullinet Software
UUCP: ...!seismo!harvard!mit-eddie!cullvax!drw
ARPA: cullvax!drw@eddie.mit.edu
Un*x (a generic name for a class of OS's) != Unix (AT&T's brand of such)

gwyn@brl-smoke.UUCP (04/03/87)

In article <272@qtc.UUCP> law@qtc.UUCP (Larry Westerman) writes:
>Kernighan and Ritchie, pg 181:
>No more authoritative source exists on the planet (8-).

If you happen to be living back in 1978.
C has evolved considerably since then.

cmcmanis@sun.UUCP (04/04/87)

I always though that if \0nnn created an octal constant then
\0xnnn should be used to create a hex constant. It would make
parsing the \0 case a little tougher but to me at least it seems
logical.

-- 
--Chuck McManis
uucp: {anywhere}!sun!cmcmanis   BIX: cmcmanis  ARPAnet: cmcmanis@sun.com
These opinions are my own and no one elses, but you knew that didn't you.

geller@eli.UUCP (04/05/87)

In article <5719@brl-smoke.ARPA>, gwyn@brl-smoke.ARPA (Doug Gwyn ) writes:
> In article <272@qtc.UUCP> law@qtc.UUCP (Larry Westerman) writes:
> >Kernighan and Ritchie, pg 181:
> >No more authoritative source exists on the planet (8-).
> 
> If you happen to be living back in 1978.
> C has evolved considerably since then.

Now don't jump to conclusions. The planet wasn't specified.

David Geller
D.C.