Null revisited (briefly)

Doug Gwyn gwyn at smoke.BRL.MIL
Wed Mar 1 15:57:12 AEST 1989


In article <1783 at dlvax2.datlog.co.uk> scm at datlog.co.uk ( Steve Mawer ) writes:
>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.
>Not if he knows the C language.  A single character written within
>single quotes is a *character constant*.  This isn't an int.
>'\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.

"Open mouth, insert foot."

Ok, gang, should we beat up on him or should we be nice?

A so-called "character constant" in C, such as 'x', is an integer
constant, expressed in a funny notation, that's all.  '\0' is no
more and no less than a fancy way of writing 0.  '\012' is a fancy
way of writing 10, and so forth.  The value of 'x' is some positive
integer that is identical to the numeric code used internally to
represent the character that is normally known as "x" on the system,
when it is read from a text file via getc(), for example.  To take a
specific case, if the system primarily uses ASCII codes to represent
characters, then 'x' would most likely be exactly the same as 120.

This is not new with ANSI C; it's the way it has always been in C.



More information about the Comp.lang.c mailing list