Thread View: comp.std.c++
2 messages
2 total messages
Started by Herb Sutter
Sun, 20 Aug 1995 19:14
Re: true/false literal std question
Author: 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. ]
Re: true/false literal std question
Author: mfinney
Date: Mon, 21 Aug 1995 00:16
Date: Mon, 21 Aug 1995 00:16
23 lines
1674 bytes
1674 bytes
In <MATT.95Aug20111450@Austern>, herbs@interlog.com (Herb Sutter) writes: > 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? This is where, I think, we are fundamentally disagreeing. There is a benefit, and (to me) a major one. That is readability. I consider using '1' and '0' for logical conditions to be "bad form", and considering the number of people that define TRUE/FALSE in some variant for the preprocessor I am not alone in that feeling. As long it is a literal which can be converted to an integral value, I just don't see the problem in allowing the preprocessor to recognize the literal. If you want to use '1' and '0' there is nothing stopping you. But I don't want to do that. And the inability of the preprocessor to recognize the 'true' / 'false' literals DOES stop me from writing (what I consider to be) readable code. Michael Lee Finney --- [ 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. ]
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads