integer value of multi-char constants

David Lai lai at mips.COM
Tue Oct 17 12:43:49 AEST 1989


Below is an example of a possible bug in various C compilers, it has to
do with converting multi-character constants to integer values:

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?

In section 3.1.3.4, it states that the value of an integer character constant
containing of more than one char,..., is implementation defined.  So seemingly
it is legal to map all multi-char constants to random values, and the above
cases indicate a conforming behaviour.  But is it intuitive that the above two
expressions can co-exist together?

I beleive the bug (if it is a bug) is inherent in all pcc
implementations.  I would like to know if there are some C implementations
out there in which the above is not true.

If you want to try this on a sun(3), you will have to use:
	'\377\000' and '\377\001'
for unknown reasons.

-- 
        "What is a DJ if he can't scratch?"  - Uncle Jamms Army
     David Lai (lai at mips.com || {ames,prls,pyramid,decwrl}!mips!lai)



More information about the Comp.std.c mailing list