Path: utzoo!attcan!uunet!lll-winken!ncis.llnl.gov!helios.ee.lbl.gov!nosc!ucsd!rutgers!cmcl2!adm!smoke!gwyn From: gwyn@smoke.BRL.MIL (Doug Gwyn ) Newsgroups: comp.lang.c Subject: Re: Null revisited (briefly) Message-ID: <9754@smoke.BRL.MIL> Date: 1 Mar 89 05:57:12 GMT References: <13068@steinmetz.ge.com> <102@servio.UUCP> <10138@socslgw.csl.sony.JUNET> <1783@dlvax2.datlog.co.uk> Reply-To: gwyn@brl.arpa (Doug Gwyn (VLD/VMB) ) Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 25 In article <1783@dlvax2.datlog.co.uk> scm@datlog.co.uk ( Steve Mawer ) writes: >In article <10138@socslgw.csl.sony.JUNET> diamond@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.