Article View: comp.std.c++
Article #1753Re: true/false literal std question
From: Herb Sutter
Date: Sun, 20 Aug 1995 19:14
Date: Sun, 20 Aug 1995 19:14
57 lines
3507 bytes
3507 bytes
Distribution: clamage@Eng.Sun.COM (Steve Clamage) writes: > >mfinney@inmind.com writes: > >>In <4167na$nv9@engnews2.Eng.Sun.COM>, herbs@interlog.com (Herb Sutter) writes: >>>Here's the point that's perhaps being missed: The problem which the built-in >>>type 'bool' (and the literals 'true' and 'false') fixed does not exist in the >>>preprocessor (no automatic conversions, etc.), so unless you can correct me >>>and point out a benefit to suddenly putting a type into the preproc, I'm >>>afraid I don't see your point. > >>Herb, since 'true' is a literal, I should be able to write 'true" as a constant in >>both the preprocessor and in C++ itself. The benefit is that you don't have >>two or more multiple names for exactly the same thing. And again, you do >>NOT introduce a type in the preprocessor by allowing it to recognize a >>literal. Why does everybody keep talking about "types" when I am talking >>about "literals"? The strings '0' and 'a' but nobody worries that the >>preprocessor needs to interpret '0' as a "type" of int and 'a' as a "type" of >>char. The point is that you wouldn't be including 'true' and 'false' into the preproc with the same meaning as in the language; they would only be macros for 1 and 0, respectively. Since we're gaining none of the benefits of the literals, why bother introducing them (with yet another meaning)? Why not just use 1 and 0 with no renaming at all? They do give a benefit in the language itself, but none of those benefits apply here. That's what I'm trying to get at. >If true and false were introduced into the preprocessor, they would >have to be predefined to the preprocessor numbers 1 and 0. They would >then be the only prefined literals in the preprocessor. Why would this >be superior to just using 1 and 0 in your code, given that there are >no types to begin with? That is, IMHO 'true' gives no advantage >whatever over '1' in a preprocessor expression, since it cannot mean >anything different from '1', and since it must iteract with expressions >with integer (not boolean) values. Steve's last phrase may answer your question about 'why is everyone talking about types when I'm talking about literals'... there are no types in the preproc, and if we included the literals 'true' and 'false' as you ask then either: a) we introduce a type into the preproc to let these two literals maintain their existing meaning; or b) the literals lose their existing meaning anyway and aren't (can't be) any different from plain 1 and 0, which doesn't seem to achieve much of anything in particular. Hence the mini-discussion of (a) and reasons to avoid it. :-) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Herb Sutter 2228 Urwin, Ste 102 voice (416) 618-0184 Connected Object Solutions Oakville ON Canada L6L 2T2 fax (905) 847-6019 --- [ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu. Contact address: std-c++-request@ncar.ucar.edu. The moderation policy is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID:
<MATT.95Aug20111450@Austern>Path:
arc1-ca.pugleaf.net!howland.reston.ans.net!agate!agate!MattShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!howland.reston.ans.net!agate!agate!Matt From: herbs@interlog.com (Herb Sutter) Newsgroups: comp.std.c++ Subject: Re: true/false literal std question Date: 20 Aug 1995 19:14:50 GMT Organization: Daystar Software Systems Design Inc. Approved: Matt@Austern Message-ID: <MATT.95Aug20111450@Austern> NNTP-Posting-Host: austern.hip.berkeley.edu