Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #93399 > unrolled thread
| Started by | thiago.adams@gmail.com |
|---|---|
| First post | 2016-09-12 13:24 -0700 |
| Last post | 2016-09-17 17:14 -0700 |
| Articles | 20 on this page of 86 — 16 participants |
Back to article view | Back to comp.lang.c
Why _Bool was not defined as enum in C99? thiago.adams@gmail.com - 2016-09-12 13:24 -0700
Re: Why _Bool was not defined as enum in C99? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-09-12 21:56 +0100
Re: Why _Bool was not defined as enum in C99? Keith Thompson <kst-u@mib.org> - 2016-09-12 15:59 -0700
Re: Why _Bool was not defined as enum in C99? Tim Rentsch <txr@alumni.caltech.edu> - 2016-09-13 16:05 -0700
Re: Why _Bool was not defined as enum in C99? Keith Thompson <kst-u@mib.org> - 2016-09-13 18:17 -0700
Re: Why _Bool was not defined as enum in C99? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-09-14 01:20 +0100
Re: Why _Bool was not defined as enum in C99? Tim Rentsch <txr@alumni.caltech.edu> - 2016-09-14 03:59 -0700
Re: Why _Bool was not defined as enum in C99? Nobody <nobody@nowhere.invalid> - 2016-09-14 17:31 +0100
Re: Why _Bool was not defined as enum in C99? Thiago Adams <thiago.adams@gmail.com> - 2016-09-14 09:49 -0700
Re: Why _Bool was not defined as enum in C99? Keith Thompson <kst-u@mib.org> - 2016-09-14 11:45 -0700
Re: Why _Bool was not defined as enum in C99? <william@wilbur.25thandClement.com> - 2016-09-14 14:13 -0700
Re: Why _Bool was not defined as enum in C99? Keith Thompson <kst-u@mib.org> - 2016-09-14 16:26 -0700
Re: Why _Bool was not defined as enum in C99? "James R. Kuyper" <jameskuyper@verizon.net> - 2016-09-12 17:11 -0400
Re: Why _Bool was not defined as enum in C99? Tim Rentsch <txr@alumni.caltech.edu> - 2016-09-13 15:55 -0700
Re: Why _Bool was not defined as enum in C99? Keith Thompson <kst-u@mib.org> - 2016-09-13 18:08 -0700
Re: Why _Bool was not defined as enum in C99? Tim Rentsch <txr@alumni.caltech.edu> - 2016-09-14 03:56 -0700
Re: Why _Bool was not defined as enum in C99? supercat@casperkitty.com - 2016-09-14 07:58 -0700
Re: Why _Bool was not defined as enum in C99? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-09-14 19:39 +0100
Re: Why _Bool was not defined as enum in C99? Keith Thompson <kst-u@mib.org> - 2016-09-14 13:52 -0700
Re: Why _Bool was not defined as enum in C99? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-09-15 00:53 +0100
Re: Why _Bool was not defined as enum in C99? supercat@casperkitty.com - 2016-09-14 17:04 -0700
Re: Why _Bool was not defined as enum in C99? Keith Thompson <kst-u@mib.org> - 2016-09-14 20:52 -0700
Re: Why _Bool was not defined as enum in C99? supercat@casperkitty.com - 2016-09-14 19:26 -0700
Re: Why _Bool was not defined as enum in C99? Keith Thompson <kst-u@mib.org> - 2016-09-14 19:04 -0700
Re: Why _Bool was not defined as enum in C99? supercat@casperkitty.com - 2016-09-14 14:21 -0700
Re: Why _Bool was not defined as enum in C99? Keith Thompson <kst-u@mib.org> - 2016-09-14 16:23 -0700
Re: Why _Bool was not defined as enum in C99? supercat@casperkitty.com - 2016-09-14 17:06 -0700
Re: Why _Bool was not defined as enum in C99? Keith Thompson <kst-u@mib.org> - 2016-09-14 20:45 -0700
Re: Why _Bool was not defined as enum in C99? Jerry Stuckle <jstucklex@attglobal.net> - 2016-09-14 22:12 -0400
Re: Why _Bool was not defined as enum in C99? David Brown <david.brown@hesbynett.no> - 2016-09-15 12:37 +0200
Re: Why _Bool was not defined as enum in C99? supercat@casperkitty.com - 2016-09-15 09:35 -0700
Re: Why _Bool was not defined as enum in C99? David Brown <david.brown@hesbynett.no> - 2016-09-16 00:47 +0200
Re: Why _Bool was not defined as enum in C99? supercat@casperkitty.com - 2016-09-15 22:02 -0700
Re: Why _Bool was not defined as enum in C99? David Brown <david.brown@hesbynett.no> - 2016-09-16 09:56 +0200
Re: Why _Bool was not defined as enum in C99? supercat@casperkitty.com - 2016-09-16 07:34 -0700
Re: Why _Bool was not defined as enum in C99? David Brown <david.brown@hesbynett.no> - 2016-09-16 20:31 +0200
Re: Why _Bool was not defined as enum in C99? supercat@casperkitty.com - 2016-09-16 12:32 -0700
Re: Why _Bool was not defined as enum in C99? David Brown <david.brown@hesbynett.no> - 2016-09-17 23:30 +0200
Re: Why _Bool was not defined as enum in C99? BartC <bc@freeuk.com> - 2016-09-15 18:25 +0100
Re: Why _Bool was not defined as enum in C99? luser droog <luser.droog@gmail.com> - 2016-09-15 12:35 -0700
Re: Why _Bool was not defined as enum in C99? David Brown <david.brown@hesbynett.no> - 2016-09-16 00:51 +0200
Re: Why _Bool was not defined as enum in C99? luser droog <luser.droog@gmail.com> - 2016-09-16 17:02 -0700
Re: Why _Bool was not defined as enum in C99? Keith Thompson <kst-u@mib.org> - 2016-09-16 19:23 -0700
Re: Why _Bool was not defined as enum in C99? David Brown <david.brown@hesbynett.no> - 2016-09-17 23:35 +0200
Re: Why _Bool was not defined as enum in C99? Keith Thompson <kst-u@mib.org> - 2016-09-14 10:40 -0700
Re: Why _Bool was not defined as enum in C99? Thiago Adams <thiago.adams@gmail.com> - 2016-09-14 10:01 -0700
Re: Why _Bool was not defined as enum in C99? supercat@casperkitty.com - 2016-09-14 11:35 -0700
Re: Why _Bool was not defined as enum in C99? Jerry Stuckle <jstucklex@attglobal.net> - 2016-09-14 22:15 -0400
Re: Why _Bool was not defined as enum in C99? supercat@casperkitty.com - 2016-09-14 23:51 -0700
Re: Why _Bool was not defined as enum in C99? Jerry Stuckle <jstucklex@attglobal.net> - 2016-09-15 15:14 -0400
Re: Why _Bool was not defined as enum in C99? Ian Collins <ian-news@hotmail.com> - 2016-09-15 16:08 +1200
Re: Why _Bool was not defined as enum in C99? David Brown <david.brown@hesbynett.no> - 2016-09-15 12:46 +0200
Re: Why _Bool was not defined as enum in C99? supercat@casperkitty.com - 2016-09-15 09:37 -0700
Re: Why _Bool was not defined as enum in C99? David Brown <david.brown@hesbynett.no> - 2016-09-16 00:53 +0200
Re: Why _Bool was not defined as enum in C99? supercat@casperkitty.com - 2016-09-15 21:45 -0700
Re: Why _Bool was not defined as enum in C99? Richard Heathfield <rjh@cpax.org.uk> - 2016-09-16 06:32 +0100
Re: Why _Bool was not defined as enum in C99? David Brown <david.brown@hesbynett.no> - 2016-09-16 09:59 +0200
Re: Why _Bool was not defined as enum in C99? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-09-16 11:00 +0100
Re: Why _Bool was not defined as enum in C99? Thiago Adams <thiago.adams@gmail.com> - 2016-09-16 04:46 -0700
Re: Why _Bool was not defined as enum in C99? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-09-16 12:58 +0100
Re: Why _Bool was not defined as enum in C99? Melzzzzz <Melzzzzz@zzzzz.com> - 2016-09-16 12:06 +0000
Re: Why _Bool was not defined as enum in C99? Thiago Adams <thiago.adams@gmail.com> - 2016-09-16 05:13 -0700
Re: Why _Bool was not defined as enum in C99? Keith Thompson <kst-u@mib.org> - 2016-09-16 10:47 -0700
Re: Why _Bool was not defined as enum in C99? Keith Thompson <kst-u@mib.org> - 2016-09-16 10:46 -0700
Re: Why _Bool was not defined as enum in C99? David Brown <david.brown@hesbynett.no> - 2016-09-16 10:02 +0200
Re: Why _Bool was not defined as enum in C99? Tim Rentsch <txr@alumni.caltech.edu> - 2016-09-15 11:42 -0700
Re: Why _Bool was not defined as enum in C99? David Brown <david.brown@hesbynett.no> - 2016-09-16 10:19 +0200
Re: Why _Bool was not defined as enum in C99? Tim Rentsch <txr@alumni.caltech.edu> - 2016-09-16 08:06 -0700
Re: Why _Bool was not defined as enum in C99? David Brown <david.brown@hesbynett.no> - 2016-09-16 20:51 +0200
Re: Why _Bool was not defined as enum in C99? Thiago Adams <thiago.adams@gmail.com> - 2016-09-16 11:56 -0700
Re: Why _Bool was not defined as enum in C99? Tim Rentsch <txr@alumni.caltech.edu> - 2016-09-22 22:38 -0700
Re: Why _Bool was not defined as enum in C99? Tim Rentsch <txr@alumni.caltech.edu> - 2016-09-14 11:42 -0700
Re: Why _Bool was not defined as enum in C99? Keith Thompson <kst-u@mib.org> - 2016-09-14 14:02 -0700
Re: Why _Bool was not defined as enum in C99? Tim Rentsch <txr@alumni.caltech.edu> - 2016-09-15 10:51 -0700
Re: Why _Bool was not defined as enum in C99? supercat@casperkitty.com - 2016-09-15 11:18 -0700
Re: Why _Bool was not defined as enum in C99? Keith Thompson <kst-u@mib.org> - 2016-09-15 13:46 -0700
Re: Why _Bool was not defined as enum in C99? supercat@casperkitty.com - 2016-09-15 13:10 -0700
Re: Why _Bool was not defined as enum in C99? Keith Thompson <kst-u@mib.org> - 2016-09-15 16:01 -0700
Re: Why _Bool was not defined as enum in C99? Keith Thompson <kst-u@mib.org> - 2016-09-15 13:40 -0700
Re: Why _Bool was not defined as enum in C99? Tim Rentsch <txr@alumni.caltech.edu> - 2016-09-16 07:21 -0700
Re: Why _Bool was not defined as enum in C99? Thiago Adams <thiago.adams@gmail.com> - 2016-09-16 07:37 -0700
Re: Why _Bool was not defined as enum in C99? David Brown <david.brown@hesbynett.no> - 2016-09-16 20:55 +0200
Re: Why _Bool was not defined as enum in C99? Keith Thompson <kst-u@mib.org> - 2016-09-16 14:43 -0700
Re: Why _Bool was not defined as enum in C99? supercat@casperkitty.com - 2016-09-16 15:36 -0700
Re: Why _Bool was not defined as enum in C99? David Brown <david.brown@hesbynett.no> - 2016-09-17 23:45 +0200
Re: Why _Bool was not defined as enum in C99? Keith Thompson <kst-u@mib.org> - 2016-09-17 17:14 -0700
Page 1 of 5 [1] 2 3 4 5 Next page →
| From | thiago.adams@gmail.com |
|---|---|
| Date | 2016-09-12 13:24 -0700 |
| Subject | Why _Bool was not defined as enum in C99? |
| Message-ID | <6b5aa241-0498-4e41-993b-a1ed445effb0@googlegroups.com> |
Does anyone knows if an enumeration was considered to implement _Bool?
[toc] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2016-09-12 21:56 +0100 |
| Message-ID | <871t0osuq6.fsf@bsb.me.uk> |
| In reply to | #93399 |
thiago.adams@gmail.com writes: > Does anyone knows if an enumeration was considered to implement _Bool? Well, some member of the committee must know, but sadly, I don't. However, I'd be very surprised if it had not been considered, however briefly. I image a strong reason it would not have got through is the desire to be compatible with the semantics of C++'s bool which does not behave like an enumerated type. But there are all sorts of problem with making _Bool just a plain C enumeration. For example, some conversions would be undefined, and you would have the problem of a _Bool value being something other than 0 or 1. The bottom line is that you want _Bool b = <expression>; ... if ( b ) ... to behave like if ( <expression> ) ... -- Ben.
[toc] | [prev] | [next] | [standalone]
| From | Keith Thompson <kst-u@mib.org> |
|---|---|
| Date | 2016-09-12 15:59 -0700 |
| Message-ID | <lny42w67x4.fsf@kst-u.example.com> |
| In reply to | #93402 |
Ben Bacarisse <ben.usenet@bsb.me.uk> writes:
> thiago.adams@gmail.com writes:
>> Does anyone knows if an enumeration was considered to implement _Bool?
>
> Well, some member of the committee must know, but sadly, I don't.
> However, I'd be very surprised if it had not been considered, however
> briefly.
>
> I image a strong reason it would not have got through is the desire to
> be compatible with the semantics of C++'s bool which does not behave
> like an enumerated type.
>
> But there are all sorts of problem with making _Bool just a plain C
> enumeration. For example, some conversions would be undefined, and you
> would have the problem of a _Bool value being something other than 0 or
> 1.
>
> The bottom line is that you want
>
> _Bool b = <expression>;
> ...
> if ( b ) ...
>
> to behave like
>
> if ( <expression> ) ...
_Bool is an unsigned integer type that, in some ways, doesn't behave
like other unsigned integer types, particularly in the way values
of other types are converted to _Bool.
The committee could, in principle, have made _Bool an enumerated type
that behaves differently from other enumerated types. (There is some
precedent; in Ada, Boolean is an enumerated type with some special
properties.) But IMHO making it an unsigned integer type is simpler.
For one thing, predefined integer types are not defined anywhere;
an enumerated _Bool would be unique in having no declaration in
any C source code.
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
[toc] | [prev] | [next] | [standalone]
| From | Tim Rentsch <txr@alumni.caltech.edu> |
|---|---|
| Date | 2016-09-13 16:05 -0700 |
| Message-ID | <kfn8tuvjt8u.fsf@x-alumni2.alumni.caltech.edu> |
| In reply to | #93402 |
Ben Bacarisse <ben.usenet@bsb.me.uk> writes: > thiago.adams@gmail.com writes: > >> Does anyone knows if an enumeration was considered to implement _Bool? > > I image a strong reason it would not have got through is the desire to > be compatible with the semantics of C++'s bool which does not behave > like an enumerated type. [...] I believe bool in C++ and _Bool in C were developed more or less contemporaneously. (C++ added 'bool' in C++98.) That doesn't contradict your statement, but it suggests the relationship may have been one more of synergy than causality. (Let me emphasize that I have no facts beyond when 'bool' was added to C++. I don't know anything, I'm just speculating.)
[toc] | [prev] | [next] | [standalone]
| From | Keith Thompson <kst-u@mib.org> |
|---|---|
| Date | 2016-09-13 18:17 -0700 |
| Message-ID | <lnpoo75lfc.fsf@kst-u.example.com> |
| In reply to | #93449 |
Tim Rentsch <txr@alumni.caltech.edu> writes:
> Ben Bacarisse <ben.usenet@bsb.me.uk> writes:
>
>> thiago.adams@gmail.com writes:
>>
>>> Does anyone knows if an enumeration was considered to implement _Bool?
>>
>> I image a strong reason it would not have got through is the desire to
>> be compatible with the semantics of C++'s bool which does not behave
>> like an enumerated type. [...]
>
> I believe bool in C++ and _Bool in C were developed more or less
> contemporaneously. (C++ added 'bool' in C++98.) That doesn't
> contradict your statement, but it suggests the relationship
> may have been one more of synergy than causality. (Let me
> emphasize that I have no facts beyond when 'bool' was added
> to C++. I don't know anything, I'm just speculating.)
Hmm. C++98 was the first C++ standard. Did pre-standard C++
not have bool before that? (I have books that would answer that,
but they're not handy.)
(The C99 Rationale doesn't provide any useful information on the
history of _Bool.)
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2016-09-14 01:20 +0100 |
| Message-ID | <87sht3nxh4.fsf@bsb.me.uk> |
| In reply to | #93453 |
Keith Thompson <kst-u@mib.org> writes: > Tim Rentsch <txr@alumni.caltech.edu> writes: >> Ben Bacarisse <ben.usenet@bsb.me.uk> writes: >> >>> thiago.adams@gmail.com writes: >>> >>>> Does anyone knows if an enumeration was considered to implement _Bool? >>> >>> I image a strong reason it would not have got through is the desire to >>> be compatible with the semantics of C++'s bool which does not behave >>> like an enumerated type. [...] >> >> I believe bool in C++ and _Bool in C were developed more or less >> contemporaneously. (C++ added 'bool' in C++98.) That doesn't >> contradict your statement, but it suggests the relationship >> may have been one more of synergy than causality. (Let me >> emphasize that I have no facts beyond when 'bool' was added >> to C++. I don't know anything, I'm just speculating.) > > Hmm. C++98 was the first C++ standard. Did pre-standard C++ > not have bool before that? (I have books that would answer that, > but they're not handy.) I don't think they did. The last version of Cfront that I used was 2.0 from 1989 and, looking online (there's no way I'd rely on my recollection!), I can see no sign of bool being implemented. -- Ben.
[toc] | [prev] | [next] | [standalone]
| From | Tim Rentsch <txr@alumni.caltech.edu> |
|---|---|
| Date | 2016-09-14 03:59 -0700 |
| Message-ID | <kfnintyiw60.fsf@x-alumni2.alumni.caltech.edu> |
| In reply to | #93453 |
Keith Thompson <kst-u@mib.org> writes:
> Tim Rentsch <txr@alumni.caltech.edu> writes:
>> Ben Bacarisse <ben.usenet@bsb.me.uk> writes:
>>
>>> thiago.adams@gmail.com writes:
>>>
>>>> Does anyone knows if an enumeration was considered to implement _Bool?
>>>
>>> I image a strong reason it would not have got through is the desire to
>>> be compatible with the semantics of C++'s bool which does not behave
>>> like an enumerated type. [...]
>>
>> I believe bool in C++ and _Bool in C were developed more or less
>> contemporaneously. (C++ added 'bool' in C++98.) That doesn't
>> contradict your statement, but it suggests the relationship
>> may have been one more of synergy than causality. (Let me
>> emphasize that I have no facts beyond when 'bool' was added
>> to C++. I don't know anything, I'm just speculating.)
>
> Hmm. C++98 was the first C++ standard. Did pre-standard C++
> not have bool before that? (I have books that would answer that,
> but they're not handy.)
I got my information here:
http://en.cppreference.com/w/cpp/language/history
[toc] | [prev] | [next] | [standalone]
| From | Nobody <nobody@nowhere.invalid> |
|---|---|
| Date | 2016-09-14 17:31 +0100 |
| Message-ID | <pan.2016.09.14.16.31.49.204000@nowhere.invalid> |
| In reply to | #93453 |
On Tue, 13 Sep 2016 18:17:59 -0700, Keith Thompson wrote: > Hmm. C++98 was the first C++ standard. Did pre-standard C++ > not have bool before that? (I have books that would answer that, > but they're not handy.) Stroustrup 2nd Ed (1991) says (p101): There is no separate boolean type in C++. The comparison operators == != < <= > >= return the integer 1 if the comparison is true and 0 otherwise. It is not uncommon to see TRUE defined as 1 and FALSE defined as 0.
[toc] | [prev] | [next] | [standalone]
| From | Thiago Adams <thiago.adams@gmail.com> |
|---|---|
| Date | 2016-09-14 09:49 -0700 |
| Message-ID | <d0979b66-f233-4040-84be-9fdde324b192@googlegroups.com> |
| In reply to | #93464 |
On Wednesday, September 14, 2016 at 1:31:56 PM UTC-3, Nobody wrote: > On Tue, 13 Sep 2016 18:17:59 -0700, Keith Thompson wrote: > > > Hmm. C++98 was the first C++ standard. Did pre-standard C++ > > not have bool before that? (I have books that would answer that, > > but they're not handy.) > > Stroustrup 2nd Ed (1991) says (p101): > > There is no separate boolean type in C++. The comparison operators > > == != < <= > >= > > return the integer 1 if the comparison is true and 0 otherwise. It is not > uncommon to see TRUE defined as 1 and FALSE defined as 0. That's strange. If you look at the c++ standard it says bool is a type and true and false are literals. And these operators return bool.
[toc] | [prev] | [next] | [standalone]
| From | Keith Thompson <kst-u@mib.org> |
|---|---|
| Date | 2016-09-14 11:45 -0700 |
| Message-ID | <lnh99i5nhl.fsf@kst-u.example.com> |
| In reply to | #93465 |
Thiago Adams <thiago.adams@gmail.com> writes:
> On Wednesday, September 14, 2016 at 1:31:56 PM UTC-3, Nobody wrote:
>> On Tue, 13 Sep 2016 18:17:59 -0700, Keith Thompson wrote:
>>
>> > Hmm. C++98 was the first C++ standard. Did pre-standard C++
>> > not have bool before that? (I have books that would answer that,
>> > but they're not handy.)
>>
>> Stroustrup 2nd Ed (1991) says (p101):
>>
>> There is no separate boolean type in C++. The comparison operators
>>
>> == != < <= > >=
>>
>> return the integer 1 if the comparison is true and 0 otherwise. It is not
>> uncommon to see TRUE defined as 1 and FALSE defined as 0.
>
> That's strange. If you look at the c++ standard it says bool is a type
> and true and false are literals. And these operators return bool.
Of course the C++ *standard* does. The cited book was published in
1991. The first C++ standard was published in 1998. The "bool" type
was added some time between those dates. (I had thought "bool" was an
earlier addition; apparently I was mistaken.)
The link Tim posted
http://en.cppreference.com/w/cpp/language/history
shows bool as a new feature in the C++98 standard.
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
[toc] | [prev] | [next] | [standalone]
| From | <william@wilbur.25thandClement.com> |
|---|---|
| Date | 2016-09-14 14:13 -0700 |
| Message-ID | <15road-l18.ln1@wilbur.25thandClement.com> |
| In reply to | #93453 |
Keith Thompson <kst-u@mib.org> wrote: > Tim Rentsch <txr@alumni.caltech.edu> writes: >> Ben Bacarisse <ben.usenet@bsb.me.uk> writes: >> >>> thiago.adams@gmail.com writes: >>> >>>> Does anyone knows if an enumeration was considered to implement _Bool? >>> >>> I image a strong reason it would not have got through is the desire to >>> be compatible with the semantics of C++'s bool which does not behave >>> like an enumerated type. [...] >> >> I believe bool in C++ and _Bool in C were developed more or less >> contemporaneously. (C++ added 'bool' in C++98.) That doesn't >> contradict your statement, but it suggests the relationship >> may have been one more of synergy than causality. (Let me >> emphasize that I have no facts beyond when 'bool' was added >> to C++. I don't know anything, I'm just speculating.) > > Hmm. C++98 was the first C++ standard. Did pre-standard C++ > not have bool before that? (I have books that would answer that, > but they're not handy.) > > (The C99 Rationale doesn't provide any useful information on the > history of _Bool.) I don't know if this was the proposal actually adopted, but there's a rationale included in N815 which explains, in part, "The solution is to standardize a Boolean type. This could have been implemented in any one of the ways that C developers have used in the past, or as a type built into the language. The committee chose the latter because it is linguistically cleaner. It gives the translator direct knowledge of the type, which allows consistent promotion rules to be defined and which may expose new opportunities for optimization as well." -- http://www.open-std.org/jtc1/sc22/wg14/www/docs/n815.htm N815 is one of the first hits when using the Google search site:http://www.open-std.org/jtc1/sc22/wg14/www/docs _Bool
[toc] | [prev] | [next] | [standalone]
| From | Keith Thompson <kst-u@mib.org> |
|---|---|
| Date | 2016-09-14 16:26 -0700 |
| Message-ID | <lnr38m3vwh.fsf@kst-u.example.com> |
| In reply to | #93489 |
<william@wilbur.25thandClement.com> writes:
> Keith Thompson <kst-u@mib.org> wrote:
>> Tim Rentsch <txr@alumni.caltech.edu> writes:
>>> Ben Bacarisse <ben.usenet@bsb.me.uk> writes:
>>>
>>>> thiago.adams@gmail.com writes:
>>>>
>>>>> Does anyone knows if an enumeration was considered to implement _Bool?
>>>>
>>>> I image a strong reason it would not have got through is the desire to
>>>> be compatible with the semantics of C++'s bool which does not behave
>>>> like an enumerated type. [...]
>>>
>>> I believe bool in C++ and _Bool in C were developed more or less
>>> contemporaneously. (C++ added 'bool' in C++98.) That doesn't
>>> contradict your statement, but it suggests the relationship
>>> may have been one more of synergy than causality. (Let me
>>> emphasize that I have no facts beyond when 'bool' was added
>>> to C++. I don't know anything, I'm just speculating.)
>>
>> Hmm. C++98 was the first C++ standard. Did pre-standard C++
>> not have bool before that? (I have books that would answer that,
>> but they're not handy.)
>>
>> (The C99 Rationale doesn't provide any useful information on the
>> history of _Bool.)
>
> I don't know if this was the proposal actually adopted, but there's a
> rationale included in N815 which explains, in part,
>
> "The solution is to standardize a Boolean type. This could have been
> implemented in any one of the ways that C developers have used in the
> past, or as a type built into the language. The committee chose the latter
> because it is linguistically cleaner. It gives the translator direct
> knowledge of the type, which allows consistent promotion rules to be
> defined and which may expose new opportunities for optimization as well."
>
> -- http://www.open-std.org/jtc1/sc22/wg14/www/docs/n815.htm
>
> N815 is one of the first hits when using the Google search
>
> site:http://www.open-std.org/jtc1/sc22/wg14/www/docs _Bool
Interesting, thanks.
The changes described in N815 are very close to what's in C99. (There
may be a few minor wording changes; I haven't checked.)
Note that there's no mention of C++ -- which neither confirms nor denies
that C's _Bool was inspired by C++'s bool.
In the Conclusion section, it says:
The above changes will bring C9X into alignment with the committee's
decision by adding a first class Boolean type.
Which implies that there was a decision, perhaps documented in some
minutes somewhere, that preceded the writing of N815.
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
[toc] | [prev] | [next] | [standalone]
| From | "James R. Kuyper" <jameskuyper@verizon.net> |
|---|---|
| Date | 2016-09-12 17:11 -0400 |
| Message-ID | <9df5c6d1-ee1f-a094-fc32-76895b79d7ba@verizon.net> |
| In reply to | #93399 |
On 09/12/2016 04:24 PM, thiago.adams@gmail.com wrote: > > Does anyone knows if an enumeration was considered to implement _Bool? Yes, someone does know - most (hopefully, all?) of the people who participated in that decision are still alive. I'm not one of those people. The best I can do is read the C99 Rational - which doesn't discuss that issue. Discussions of that possibility that I could review might have occurred on comp.std.c, but I can find no such discussions. The standard itself imposes only requirements on the behavior of _Bool, not on how it is implemented. The key feature that distinguishes _Bool from other integer types is that "When any scalar value is converted to _Bool, the result is 0 if the value compares equal to 0; otherwise, the result is 1." (6.3.1.2p1) Therefore, simply implementing _Bool as a typedef for an enumeration would not work, because type conversions wouldn't be handled correctly. An implementation that handled that conversion correctly as a special rule, and otherwise treated _Bool as though it were a typedef for an enumeration could probably be conforming, though there might be additional details I haven't thought of that would have to be dealt with.
[toc] | [prev] | [next] | [standalone]
| From | Tim Rentsch <txr@alumni.caltech.edu> |
|---|---|
| Date | 2016-09-13 15:55 -0700 |
| Message-ID | <kfnd1k7jton.fsf@x-alumni2.alumni.caltech.edu> |
| In reply to | #93399 |
thiago.adams@gmail.com writes: > Does anyone knows if an enumeration was considered to implement _Bool? It wouldn't make sense to implement _Bool as an enumeration, because by there aren't any enumeration constants that go with it.
[toc] | [prev] | [next] | [standalone]
| From | Keith Thompson <kst-u@mib.org> |
|---|---|
| Date | 2016-09-13 18:08 -0700 |
| Message-ID | <lntwdj5lv2.fsf@kst-u.example.com> |
| In reply to | #93448 |
Tim Rentsch <txr@alumni.caltech.edu> writes:
> thiago.adams@gmail.com writes:
>
>> Does anyone knows if an enumeration was considered to implement _Bool?
>
> It wouldn't make sense to implement _Bool as an enumeration,
> because by there aren't any enumeration constants that go
> with it.
Surely if _Bool were an enumerated type, false and true would be
enumeration constants.
My favorite way to define a boolean type if I can't assume C99 is
typedef enum { false, true } bool;
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
[toc] | [prev] | [next] | [standalone]
| From | Tim Rentsch <txr@alumni.caltech.edu> |
|---|---|
| Date | 2016-09-14 03:56 -0700 |
| Message-ID | <kfnmvjaiwbw.fsf@x-alumni2.alumni.caltech.edu> |
| In reply to | #93452 |
Keith Thompson <kst-u@mib.org> writes: > Tim Rentsch <txr@alumni.caltech.edu> writes: >> thiago.adams@gmail.com writes: >> >>> Does anyone knows if an enumeration was considered to implement _Bool? >> >> It wouldn't make sense to implement _Bool as an enumeration, >> because by there aren't any enumeration constants that go >> with it. > > Surely if _Bool were an enumerated type, false and true would be > enumeration constants. The point is that isn't a good fit for the existing semantics of _Bool. Part of the reason that _Bool is an integer type is that it is important that "false" be 0 and "not false" be 1 (ie, important in the sense that it is an essential aspect of the semantics of _Bool). Normally enumeration constants are used when one wants to decouple the name of a constant and its value. A key element of _Bool, as it is defined in C, and in contrast to some other languages where a boolean type is more like an enumerated type, is that it must behave like an integer with certain known values. It doesn't make sense to pretend the particular values don't matter, which having enumeration constants usually suggests. Some languages choose to neuter their boolean types in the sense that they may be used only in a boolean context (and not, eg, an arithmetic context). Personally I think that's a poor decision, and am glad C chose to adopt a more Iverson-like semantics for _Bool. Considering that choice, it follows that _Bool is better suited to a regular (arithmetic) integer type than an enumerated type.
[toc] | [prev] | [next] | [standalone]
| From | supercat@casperkitty.com |
|---|---|
| Date | 2016-09-14 07:58 -0700 |
| Message-ID | <02a1a24e-5ead-486c-8397-e68a2a79f8f7@googlegroups.com> |
| In reply to | #93458 |
On Wednesday, September 14, 2016 at 5:56:33 AM UTC-5, Tim Rentsch wrote: > Keith Thompson writes: > > Surely if _Bool were an enumerated type, false and true would be > > enumeration constants. > > The point is that isn't a good fit for the existing semantics > of _Bool. I am unaware of any "existing" semantics for _Bool before the Committee invented them; if the Committee had simply used an enumerated type, the semantics of enumerated types would--by definition--have fit perfectly. Some compilers did have pre-existing semantics for single-bit variables, but the defined behaviors of the _Bool type are not compatible with any predecessors that I know of.
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2016-09-14 19:39 +0100 |
| Message-ID | <8760pynx50.fsf@bsb.me.uk> |
| In reply to | #93461 |
supercat@casperkitty.com writes: > On Wednesday, September 14, 2016 at 5:56:33 AM UTC-5, Tim Rentsch wrote: >> Keith Thompson writes: >> > Surely if _Bool were an enumerated type, false and true would be >> > enumeration constants. >> >> The point is that isn't a good fit for the existing semantics >> of _Bool. > > I am unaware of any "existing" semantics for _Bool before the Committee > invented them; Yes, there are. Obviously not for _Bool itself -- that did not exist -- but in "if (...)", "while (...)" and as operands of &&, || and ! an expression is treated as being Boolean. > if the Committee had simply used an enumerated type, the > semantics of enumerated types would--by definition--have fit > perfectly. You'd have expressions E such that if ((_Bool)E) and if (E) behave differently. <snip> -- Ben.
[toc] | [prev] | [next] | [standalone]
| From | Keith Thompson <kst-u@mib.org> |
|---|---|
| Date | 2016-09-14 13:52 -0700 |
| Message-ID | <lnd1k65hmr.fsf@kst-u.example.com> |
| In reply to | #93469 |
Ben Bacarisse <ben.usenet@bsb.me.uk> writes:
> supercat@casperkitty.com writes:
[...]
>> if the Committee had simply used an enumerated type, the
>> semantics of enumerated types would--by definition--have fit
>> perfectly.
>
> You'd have expressions E such that
>
> if ((_Bool)E)
>
> and
>
> if (E)
>
> behave differently.
>
> <snip>
Not if the hypothetical enumerated _Bool has the same conversion
semantics as the built-in _Bool that was actually added in C99.
I don't think anyone is suggesting just adding the equivalent of
a predefined
typedef enum { false, true } _Bool;
and leaving it at that.
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2016-09-15 00:53 +0100 |
| Message-ID | <87twdim428.fsf@bsb.me.uk> |
| In reply to | #93476 |
Keith Thompson <kst-u@mib.org> writes:
> Ben Bacarisse <ben.usenet@bsb.me.uk> writes:
>> supercat@casperkitty.com writes:
> [...]
>>> if the Committee had simply used an enumerated type, the
>>> semantics of enumerated types would--by definition--have fit
>>> perfectly.
>>
>> You'd have expressions E such that
>>
>> if ((_Bool)E)
>>
>> and
>>
>> if (E)
>>
>> behave differently.
>>
>> <snip>
>
> Not if the hypothetical enumerated _Bool has the same conversion
> semantics as the built-in _Bool that was actually added in C99.
> I don't think anyone is suggesting just adding the equivalent of
> a predefined
>
> typedef enum { false, true } _Bool;
>
> and leaving it at that.
Actually, I thought that was exactly what the OP was asking about. And
it sounds like it is what supercat was talking about in the message I
replied to. That's how I read "if the Committee had simply used an
enumerated type" and the idea that the semantics would be right by
definition.
But if it's a special enumeration with its own conversion semantics, how
do you know that is *not* how _Bool is implemented? Or, to put it
slightly differently, what would give the game away so you could say
that it's a special enumerated type with its own semantics?
--
Ben.
[toc] | [prev] | [next] | [standalone]
Page 1 of 5 [1] 2 3 4 5 Next page →
Back to top | Article view | comp.lang.c
csiph-web