Null revisited (briefly)
Chris Torek
chris at mimsy.UUCP
Wed Mar 1 21:58:01 AEST 1989
>In article <10138 at socslgw.csl.sony.JUNET> diamond at diamond.
>(Norman Diamond) writes:
>>When you assign 'x' to a character, you are assigning an int to a
>>character. The reader knows that the type mismatch was intentional.
This is correct.
In article <1783 at dlvax2.datlog.co.uk> scm at datlog.co.uk ( Steve Mawer ) writes:
>Not if he knows the C language. A single character written within
>single quotes is a *character constant*. This isn't an int.
False. A character constant is an int (not a char) whose value is the
representation of that character in the machine's character set
(typically ASCII; EBCDIC is confused about where the []s go, and
sometimes does not have {} \ and ~, depending on which EBCDIC you
are using---there are at least three major variants).
>'\0' is a special case to permit the representation of non-graphical
>characters (also newline, tab, backslash, return, etc.) and is not
>the same as 0, which is an integer constant.
Aside from the backslash interpretation, '\0' is *not* a special case.
The type of '\0' is int and its value is zero, no matter what the
character set; this is guaranteed by the C language. (The <type,value>
pair for an unadorned 0 is also <int,0>, although the <type,value>
pair of something like 65432 is sometimes <long,65432>.)
>It should, however, be noted that some compilers will allow the use
>of multiple characters, as in 'abcd' (which *may* work on 32 bit
>machines). I wouldn't recommend this usage in portable software.
This is correct. It is hard to predict whether (char)'abcd' will
be the same as (char)'a' or (char)'d' (or even b or c), so it is
best to avoid these.
--
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain: chris at mimsy.umd.edu Path: uunet!mimsy!chris
More information about the Comp.lang.c
mailing list