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 | 6 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 5 of 5 — ← Prev page 1 2 3 4 [5]
| From | Thiago Adams <thiago.adams@gmail.com> |
|---|---|
| Date | 2016-09-16 07:37 -0700 |
| Message-ID | <405dbd3c-fe4d-41cc-90af-85b319304003@googlegroups.com> |
| In reply to | #93620 |
On Friday, September 16, 2016 at 11:21:25 AM UTC-3, Tim Rentsch wrote: > In my view there is no reason (in C) to define false and > true at all - the constants 0 and 1 do just fine. I find it > puzzling that lots of people seem to have the opposite > reaction. But I'm not out to change anyone's mind, so maybe > it's better to leave that conversation for another day. The same view applies for NULL. Do you like 0 for null? C++ has nullptr_t and nullptr. We can think nullptr_t as a enum with just one value nullptr. (The semantics are very different from enums, but just to show that both have value constrains) I like to use true, false, NULL and not 1 , 0 , 0.
[toc] | [prev] | [next] | [standalone]
| From | David Brown <david.brown@hesbynett.no> |
|---|---|
| Date | 2016-09-16 20:55 +0200 |
| Message-ID | <nrhf6u$24m$1@dont-email.me> |
| In reply to | #93623 |
On 16/09/16 16:37, Thiago Adams wrote: > On Friday, September 16, 2016 at 11:21:25 AM UTC-3, Tim Rentsch wrote: > >> In my view there is no reason (in C) to define false and >> true at all - the constants 0 and 1 do just fine. I find it >> puzzling that lots of people seem to have the opposite >> reaction. But I'm not out to change anyone's mind, so maybe >> it's better to leave that conversation for another day. > > The same view applies for NULL. Do you like 0 for null? > > C++ has nullptr_t and nullptr. > We can think nullptr_t as a enum with just one value nullptr. > (The semantics are very different from enums, but just to show that both have value constrains) > > I like to use true, false, NULL and not 1 , 0 , 0. > nullptr and nullptr_t have a very specific reason for their existence. NULL is basically just a symbol meaning 0, that people can use if they think it makes their code clearer. But nullptr exists to let function overrides and template matching distinguish between the integer constant 0, and a null pointer. (Personally, I prefer "true" and "false" for bools - but I might use 1 and 0 if I were storing a boolean value in an integer type. And I might use either 0 or NULL for a null pointer, whichever I think makes most sense at the time.)
[toc] | [prev] | [next] | [standalone]
| From | Keith Thompson <kst-u@mib.org> |
|---|---|
| Date | 2016-09-16 14:43 -0700 |
| Message-ID | <lnoa3nzfjl.fsf@kst-u.example.com> |
| In reply to | #93653 |
David Brown <david.brown@hesbynett.no> writes:
[...]
> nullptr and nullptr_t have a very specific reason for their existence.
> NULL is basically just a symbol meaning 0, that people can use if they
> think it makes their code clearer. But nullptr exists to let function
> overrides and template matching distinguish between the integer constant
> 0, and a null pointer.
NULL isn't just 0. In C, NULL expands to an implementation-defined
null pointer constant. It can be either `0`, or `((void*)0)`,
or any of a number of other things (including `('/'/'/'-'/'/'/')`,
which is of course deliberately silly).
> (Personally, I prefer "true" and "false" for bools - but I might use 1
> and 0 if I were storing a boolean value in an integer type.
Personally, I prefer to store boolean values in booleans and integer
values in integers. Of course C doesn't always make that easy.
> And I might
> use either 0 or NULL for a null pointer, whichever I think makes most
> sense at the time.)
When would 0 make more sense than NULL?
--
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 | supercat@casperkitty.com |
|---|---|
| Date | 2016-09-16 15:36 -0700 |
| Message-ID | <375977ae-2788-4bb8-b7e1-774653c6c6ab@googlegroups.com> |
| In reply to | #93659 |
On Friday, September 16, 2016 at 2:38:23 PM UTC-5, Keith Thompson wrote:
> When would 0 make more sense than NULL?
How about when using "{0}" to represent the contents of a structure whose
members should all be default-initialized, and whose first member might
happen to be a pointer?
[toc] | [prev] | [next] | [standalone]
| From | David Brown <david.brown@hesbynett.no> |
|---|---|
| Date | 2016-09-17 23:45 +0200 |
| Message-ID | <nrkdh3$iji$1@dont-email.me> |
| In reply to | #93659 |
On 16/09/16 23:43, Keith Thompson wrote:
> David Brown <david.brown@hesbynett.no> writes:
> [...]
>> nullptr and nullptr_t have a very specific reason for their existence.
>> NULL is basically just a symbol meaning 0, that people can use if they
>> think it makes their code clearer. But nullptr exists to let function
>> overrides and template matching distinguish between the integer constant
>> 0, and a null pointer.
>
> NULL isn't just 0. In C, NULL expands to an implementation-defined
> null pointer constant. It can be either `0`, or `((void*)0)`,
> or any of a number of other things (including `('/'/'/'-'/'/'/')`,
> which is of course deliberately silly).
That is true - but I think "NULL is basically just a symbol meaning 0"
is a reasonable simplification. You can't necessarily use NULL in all
situations where you can use 0 ("int x = NULL;" won't work if NULL is
((void*) 0), for example). But in situations where you would use NULL,
you can always use 0. And unlike with nullptr in C++, there is no
difference in the meaning of your code if you use 0 instead of NULL.
>
>> (Personally, I prefer "true" and "false" for bools - but I might use 1
>> and 0 if I were storing a boolean value in an integer type.
>
> Personally, I prefer to store boolean values in booleans and integer
> values in integers. Of course C doesn't always make that easy.
I don't normally /choose/ to store a boolean value in an integer type -
but interaction with other things (hardware registers, communication
with other devices, other people's code, etc.) can make those choices
for me.
>
>> And I might
>> use either 0 or NULL for a null pointer, whichever I think makes most
>> sense at the time.)
>
> When would 0 make more sense than NULL?
>
I can't actually think of any good examples off-hand. I have certainly
used 0 for pointer initialisation, but perhaps that's just laziness
rather than "making more sense" - in such situations, I don't see the
use of NULL as being particularly significant. When passing a null
pointer argument to a function, however, NULL is often clearer in the code.
[toc] | [prev] | [next] | [standalone]
| From | Keith Thompson <kst-u@mib.org> |
|---|---|
| Date | 2016-09-17 17:14 -0700 |
| Message-ID | <lntwdexdvm.fsf@kst-u.example.com> |
| In reply to | #93699 |
David Brown <david.brown@hesbynett.no> writes:
> On 16/09/16 23:43, Keith Thompson wrote:
>> David Brown <david.brown@hesbynett.no> writes:
>> [...]
>>> nullptr and nullptr_t have a very specific reason for their existence.
>>> NULL is basically just a symbol meaning 0, that people can use if they
>>> think it makes their code clearer. But nullptr exists to let function
>>> overrides and template matching distinguish between the integer constant
>>> 0, and a null pointer.
>>
>> NULL isn't just 0. In C, NULL expands to an implementation-defined
>> null pointer constant. It can be either `0`, or `((void*)0)`,
>> or any of a number of other things (including `('/'/'/'-'/'/'/')`,
>> which is of course deliberately silly).
>
> That is true - but I think "NULL is basically just a symbol meaning 0"
> is a reasonable simplification.
I disagree. NULL is a symbol meaning a null pointer constant. If your
simplification were reasonable, it would be reasonable to write:
int n = NULL;
(And the fact that C uses 0 to represent a null pointer is IMHO a rather
odd quirk.)
> You can't necessarily use NULL in all
> situations where you can use 0 ("int x = NULL;" won't work if NULL is
> ((void*) 0), for example). But in situations where you would use NULL,
> you can always use 0. And unlike with nullptr in C++, there is no
> difference in the meaning of your code if you use 0 instead of NULL.
There can be a difference. If NULL is defined as ((void*)0), then
printf("%p\n", 0);
has undefined behavior, but
printf("%p\n", NULL);
is well defined, with implementation-defined output. This is not a
useful distinction, since NULL can also be defined as 0, which makes
both versions UB. These:
printf("%p\n", (void*)0);
printf("%p\n", (void*)NULL);
are both correct and portable.
>>> (Personally, I prefer "true" and "false" for bools - but I might use 1
>>> and 0 if I were storing a boolean value in an integer type.
>>
>> Personally, I prefer to store boolean values in booleans and integer
>> values in integers. Of course C doesn't always make that easy.
>
> I don't normally /choose/ to store a boolean value in an integer type -
> but interaction with other things (hardware registers, communication
> with other devices, other people's code, etc.) can make those choices
> for me.
Sure. In such cases, I prefer to make the conversion explicit, for
example:
bool b = (some_int_value != 0);
Of course
bool b = some_int_value;
is perfectly valid; I just find the version with the comparison
clearer. YMMV.
[...]
--
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] | [standalone]
Page 5 of 5 — ← Prev page 1 2 3 4 [5]
Back to top | Article view | comp.lang.c
csiph-web