Path: utzoo!mnetor!uunet!lll-winken!lll-tis!ames!pacbell!att-ih!ihnp4!ihlpf!nevin1 From: nevin1@ihlpf.ATT.COM (00704a-Liber) Newsgroups: comp.lang.c++ Subject: Re: ``Character'' constants in C++. Message-ID: <4213@ihlpf.ATT.COM> Date: 31 Mar 88 00:42:41 GMT References: <26270@cca.CCA.COM> Reply-To: nevin1@ihlpf.UUCP (00704a-Liber,N.J.) Organization: AT&T Bell Laboratories - Naperville, Illinois Lines: 22 In article <26270@cca.CCA.COM> alex@CCA.CCA.COM (Alexis Layton) writes: >Why are ' ', '\n'', etc., defined as integer constants in C++, rather >than as character constants which get widened to integer when >necessary? The reason the 'x', etc., are integer constants in C++ is because they are integer constants in C (well, not really, but see my next sentence). More accurately, according to K&R section "2.7--Type Conversions", second paragraph (first edition of the book): "First, char's and int's may be freely intermixed in arithmetic expressions: every char in an expression is automatically converted to an int." Since this promotion automatically takes place in C (which is the output of many C++ translators), there is no easy way to go around it in C++ (remember, C++ does not change the basic types). If you really need it, you should be able to do what you want with the 'const char' type, but this needs storage at run-time. -- _ __ NEVIN J. LIBER ..!ihnp4!ihlpf!nevin1 (312) 510-6194 ' ) ) "The secret compartment of my ring I fill / / _ , __o ____ with an Underdog super-energy pill." / (_