Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #142442

Re: nullptr in C

From Ian Collins <ian-news@hotmail.com>
Newsgroups comp.lang.c
Subject Re: nullptr in C
Date 2019-03-26 10:25 +1300
Message-ID <gfsvauFar11U2@mid.individual.net> (permalink)
References (4 earlier) <9473b4e4-c8f0-4659-8d94-efaeb6a7dd35@googlegroups.com> <87d6403f-cb75-4f85-acba-bb180d5cb95e@googlegroups.com> <b1421d91-842c-4843-ae92-3ddbbc4fd436@googlegroups.com> <gfsoorFar11U1@mid.individual.net> <a36e160d-f425-4ef9-a08f-1e6051b71338@googlegroups.com>

Show all headers | View raw


On 26/03/2019 08:58, James Kuyper wrote:
> On Monday, March 25, 2019 at 3:33:56 PM UTC-4, Ian Collins wrote:
>> On 26/03/2019 08:23, James Kuyper wrote:
>>> On Monday, March 25, 2019 at 3:02:11 PM UTC-4, Thiago Adams wrote:
>>>> On Monday, March 25, 2019 at 3:37:16 PM UTC-3, James Kuyper wrote:
>>>>> On Sunday, March 24, 2019 at 7:52:10 AM UTC-4, Thiago Adams wrote:
>>>>>> On Friday, March 22, 2019 at 5:29:35 PM UTC-3, James Kuyper wrote:
>>>>>>> On Friday, March 22, 2019 at 3:14:48 PM UTC-4, Thiago Adams wrote:
>>>>> ...
>>>>>>>> This means that adding _Bool didn't added a new way to declare booleans,
>>>>>>>
>>>>>>> Actually, C has two ways to declare booleans, both of which were added to the language at the same time: _Bool and bool.
>>>>>>
>>>>>> Yes, I was discarding the direct use of _Bool in my mind.
>>>>>> Does anyone uses _Bool instead of bool ?
>>>>>
>>>>> Yes, I routinely use _Bool, if only to avoid having to
>>>>> #include <stdbool.h>. In my experience, the need to avoid a conflicting
>>>>> definition of "bool" comes up only rarely, but often enough to justify
>>>>> avoiding it's use. I almost never need to write code that will compile
>>>>> as both C and C++ code, with the same meaning.
>>>>
>>>> In this case, what do you use for 'true' and 'false' ?
>>>>
>>>> (Both macros are defined in stdbool.h)
>>>
>>> if(condition)
>>> if(!condition)
>>
>> As a function parameter?
>>
>>> Assuming the condition variable is suitably named, that should be a very
>>> clear, obvious way of using it.
> 
> function(boolean_expression)
> 
> I'm not saying the issue never comes up, but in most cases where I've
> used _Bool, explicit use of either true or false is unnecessary. This is
> probably the result of writing C code for more than three decades, and
> not having "true" or "false" available as part of the language for most
> of that time (the last time I worked on MODIS code, I was still covered
> by a 1997 coding guideline that required me to write for C94 (C90 + first
> two TC's)). I got pretty good at writing code that didn't need to use
> them, which isn't very difficult.
> The C++ code that I'm working on right now makes extensive use of true
> or false to initialize bool variables in all constructors - even for
> non-static data members that are explicitly set to some other value later
> on in the same constructor.

A smell for discussion in another place!

-- 
Ian.

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Re: nullptr in C Thiago Adams <thiago.adams@gmail.com> - 2019-03-22 12:14 -0700
  Re: nullptr in C James Kuyper <jameskuyper@alumni.caltech.edu> - 2019-03-22 13:29 -0700
    Re: nullptr in C Thiago Adams <thiago.adams@gmail.com> - 2019-03-24 04:51 -0700
      Re: nullptr in C William Ahern <william@25thandClement.com> - 2019-03-25 06:50 -0700
      Re: nullptr in C James Kuyper <jameskuyper@alumni.caltech.edu> - 2019-03-25 11:37 -0700
        Re: nullptr in C Thiago Adams <thiago.adams@gmail.com> - 2019-03-25 12:01 -0700
          Re: nullptr in C James Kuyper <jameskuyper@alumni.caltech.edu> - 2019-03-25 12:23 -0700
            Re: nullptr in C Ian Collins <ian-news@hotmail.com> - 2019-03-26 08:33 +1300
              Re: nullptr in C James Kuyper <jameskuyper@alumni.caltech.edu> - 2019-03-25 12:58 -0700
                Re: nullptr in C Ian Collins <ian-news@hotmail.com> - 2019-03-26 10:25 +1300
            Re: nullptr in C Keith Thompson <kst-u@mib.org> - 2019-03-25 13:15 -0700
              Re: nullptr in C James Kuyper <jameskuyper@alumni.caltech.edu> - 2019-03-25 13:21 -0700

csiph-web