integer value of multi-char constants

Chris Torek chris at mimsy.umd.edu
Tue Oct 17 16:25:48 AEST 1989


In article <29588 at gumby.mips.COM> lai at mips.COM (David Lai) writes:
>on a mips, vax, and sun the following is true:
>	'\001\377' == '\000\377';
>however on the same machines:
>	'\001\177' != '\000\177';
>The question is: does the above behaviour conform to ANSI C?

Certainly.  The more important question is `why would anyone expect
otherwise?'  (Remember that character constants are constant expressions
with type int---NOT type char!)

The machines listed above all form two-character constants by computing
(more or less) c0*256+c1 (or c1*256+c0), where c0 and c1 are the first
and second characters in the constant.  Hence '\001\177' is 0x17f and
'\000\177' is 0x07f.  It would be very strange for these to be equal.
-- 
`They were supposed to be green.'
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris at cs.umd.edu	Path:	uunet!mimsy!chris



More information about the Comp.std.c mailing list