alex@cca.CCA.COM (Alexis Layton) (03/30/88)
Why are ' ', '\n'', etc., defined as integer constants in C++, rather than as character constants which get widened to integer when necessary? This would make cout << ' ' possible, would it not? It would be possible to declare 'xx' to be a short constant and 'yyyy' to be a long constant for those programs which really use multi-character constants. Am I missing an obvious short-comming with this approach? Curiously, Alexis Layton alex@CCA.CCA.COM {decvax,cbosgd,linus}!cca!alex
nevin1@ihlpf.ATT.COM (00704a-Liber) (03/31/88)
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." / (_</_\/ <__/ / <_ These are solely MY opinions, not AT&T's, blah blah blah