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


Groups > comp.lang.c > #156402

Re: Is bool no longer a primitive data type of C/C++ ?

From Keith Thompson <Keith.S.Thompson+u@gmail.com>
Newsgroups comp.lang.c
Subject Re: Is bool no longer a primitive data type of C/C++ ?
Date 2020-11-02 16:23 -0800
Organization None to speak of
Message-ID <87h7q7s2y0.fsf@nosuchdomain.example.com> (permalink)
References (2 earlier) <vpqdncNTnKpToT3CnZ2dnUU7-K2dnZ2d@giganews.com> <875z6nu10d.fsf@bsb.me.uk> <w72dncKV3eO52T3CnZ2dnUU7-YfNnZ2d@giganews.com> <87tuu7sd6a.fsf@bsb.me.uk> <rnpvp0$r95$2@dont-email.me>

Show all headers | View raw


David Brown <david.brown@hesbynett.no> writes:
> On 02/11/2020 21:42, Ben Bacarisse wrote:
[...]
>> Pre-C99, int was used.  That was the way C was originally designed.
>> Even now, expressions like 1 > 2 have type int.  If you don't have C99,
>> you might as well use int.  It's what experienced C programmers will
>> expect, but if you really want the names,
>> 
>>   typedef enum { false, true } bool;
>> 
>> is a tolerable way to get them.
>
> You'd be better to pick a different name, like "fake_bool" or something
> that distinguishes it from a C99 "bool" (from <stdbool.h>) since the
> behaviour is different.

I haven't had to worry about pre-C99 compatibility for a long time, but
when I did I wouldn't have hesitated to use

    typedef enum { false, true } bool;

or perhaps

    #if __STDC_VERSION >= 199901L
    #include <stdbool.h>
    #else
    typedef enum { false, true } bool;
    #endif

The only issue is that I would avoid writing any code that depends on
the semantics of converting any other type to bool.  A compiler wouldn't
warn me about such code, and yes, it is a concern, but IMHO not worth
worrying about too much.

The most likely error case is if bool is 8 bits, so (bool)256 would be
0, i.e. false (definitely if it's unsigned, likely if it's signed).

-- 
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips Healthcare
void Void(void) { Void(); } /* The recursive call of the void */

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


Thread

Is bool no longer a primitive data type of C/C++ ? olcott <NoOne@NoWhere.com> - 2020-11-02 10:31 -0600
  Re: Is bool no longer a primitive data type of C/C++ ? Bonita Montero <Bonita.Montero@gmail.com> - 2020-11-02 17:35 +0100
    Re: Is bool no longer a primitive data type of C/C++ ? olcott <NoOne@NoWhere.com> - 2020-11-02 10:39 -0600
      Re: Is bool no longer a primitive data type of C/C++ ? Bonita Montero <Bonita.Montero@gmail.com> - 2020-11-02 17:55 +0100
      Re: Is bool no longer a primitive data type of C/C++ ? guinness.tony@gmail.com - 2020-11-02 09:00 -0800
      Re: Is bool no longer a primitive data type of C/C++ ? Leo <usenet@gkbrk.com> - 2020-11-03 19:50 +0300
        Re: Is bool no longer a primitive data type of C/C++ ? James Kuyper <jameskuyper@alumni.caltech.edu> - 2020-11-03 12:43 -0500
    Re: Is bool no longer a primitive data type of C/C++ ? "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2020-11-02 17:48 +0100
      Re: Is bool no longer a primitive data type of C/C++ ? olcott <NoOne@NoWhere.com> - 2020-11-02 10:50 -0600
        Re: Is bool no longer a primitive data type of C/C++ ? Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2020-11-02 10:35 -0700
          Re: Is bool no longer a primitive data type of C/C++ ? olcott <NoOne@NoWhere.com> - 2020-11-02 12:17 -0600
          Re: Is bool no longer a primitive data type of C/C++ ? James Kuyper <jameskuyper@alumni.caltech.edu> - 2020-11-02 14:03 -0500
            Re: Is bool no longer a primitive data type of C/C++ ? olcott <NoOne@NoWhere.com> - 2020-11-02 13:05 -0600
  Re: Is bool no longer a primitive data type of C/C++ ? Mike Terry <news.dead.person.stones@darjeeling.plus.com> - 2020-11-02 16:50 +0000
    Re: Is bool no longer a primitive data type of C/C++ ? olcott <NoOne@NoWhere.com> - 2020-11-02 11:07 -0600
      Re: Is bool no longer a primitive data type of C/C++ ? Bonita Montero <Bonita.Montero@gmail.com> - 2020-11-02 18:08 +0100
        Re: Is bool no longer a primitive data type of C/C++ ? olcott <NoOne@NoWhere.com> - 2020-11-02 11:11 -0600
          Re: Is bool no longer a primitive data type of C/C++ ? Bonita Montero <Bonita.Montero@gmail.com> - 2020-11-02 18:13 +0100
            Re: Is bool no longer a primitive data type of C/C++ ? olcott <NoOne@NoWhere.com> - 2020-11-02 11:25 -0600
      Re: Is bool no longer a primitive data type of C/C++ ? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2020-11-02 17:22 +0000
        Re: Is bool no longer a primitive data type of C/C++ ? olcott <NoOne@NoWhere.com> - 2020-11-02 11:26 -0600
        Re: Is bool no longer a primitive data type of C/C++ ? olcott <NoOne@NoWhere.com> - 2020-11-02 11:38 -0600
          Re: Is bool no longer a primitive data type of C/C++ ? Bonita Montero <Bonita.Montero@gmail.com> - 2020-11-02 19:01 +0100
            Re: Is bool no longer a primitive data type of C/C++ ? olcott <NoOne@NoWhere.com> - 2020-11-02 12:19 -0600
            Re: Is bool no longer a primitive data type of C/C++ ? "james...@alumni.caltech.edu" <jameskuyper@alumni.caltech.edu> - 2020-11-02 12:19 -0800
              Re: Is bool no longer a primitive data type of C/C++ ? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2020-11-29 00:09 -0800
                Re: Is bool no longer a primitive data type of C/C++ ? David Brown <david.brown@hesbynett.no> - 2020-11-29 13:41 +0100
          Re: Is bool no longer a primitive data type of C/C++ ? Richard Damon <Richard@Damon-Family.org> - 2020-11-02 13:18 -0500
            Re: Is bool no longer a primitive data type of C/C++ ? olcott <NoOne@NoWhere.com> - 2020-11-02 13:06 -0600
          Re: Is bool no longer a primitive data type of C/C++ ? "james...@alumni.caltech.edu" <jameskuyper@alumni.caltech.edu> - 2020-11-02 11:18 -0800
            Re: Is bool no longer a primitive data type of C/C++ ? olcott <NoOne@NoWhere.com> - 2020-11-02 13:42 -0600
              Re: Is bool no longer a primitive data type of C/C++ ? "james...@alumni.caltech.edu" <jameskuyper@alumni.caltech.edu> - 2020-11-02 12:39 -0800
                Re: Is bool no longer a primitive data type of C/C++ ? olcott <NoOne@NoWhere.com> - 2020-11-02 15:08 -0600
                Re: Is bool no longer a primitive data type of C/C++ ? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2020-11-29 00:14 -0800
                Re: Is bool no longer a primitive data type of C/C++ ? David Brown <david.brown@hesbynett.no> - 2020-11-29 13:53 +0100
                Re: Is bool no longer a primitive data type of C/C++ ? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2020-11-29 13:18 +0000
                Re: Is bool no longer a primitive data type of C/C++ ? David Brown <david.brown@hesbynett.no> - 2020-11-29 16:16 +0100
                Re: Is bool no longer a primitive data type of C/C++ ? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2020-11-29 17:53 -0800
                Re: Is bool no longer a primitive data type of C/C++ ? Richard Damon <Richard@Damon-Family.org> - 2020-11-29 08:19 -0500
                Re: Is bool no longer a primitive data type of C/C++ ? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2020-11-29 17:42 -0800
          Re: Is bool no longer a primitive data type of C/C++ ? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2020-11-02 20:42 +0000
            Re: Is bool no longer a primitive data type of C/C++ ? olcott <NoOne@NoWhere.com> - 2020-11-02 15:15 -0600
            Re: Is bool no longer a primitive data type of C/C++ ? David Brown <david.brown@hesbynett.no> - 2020-11-02 23:04 +0100
              Re: Is bool no longer a primitive data type of C/C++ ? olcott <NoOne@NoWhere.com> - 2020-11-02 16:24 -0600
              Re: Is bool no longer a primitive data type of C/C++ ? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2020-11-02 22:40 +0000
              Re: Is bool no longer a primitive data type of C/C++ ? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-11-02 16:23 -0800
            Re: Is bool no longer a primitive data type of C/C++ ? olcott <NoOne@NoWhere.com> - 2020-11-02 17:32 -0600
          Re: Is bool no longer a primitive data type of C/C++ ? David Brown <david.brown@hesbynett.no> - 2020-11-02 23:02 +0100
  Re: Is bool no longer a primitive data type of C/C++ ? Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2020-11-02 09:56 -0700
    Re: Is bool no longer a primitive data type of C/C++ ? Bonita Montero <Bonita.Montero@gmail.com> - 2020-11-02 18:05 +0100
      Re: Is bool no longer a primitive data type of C/C++ ? olcott <NoOne@NoWhere.com> - 2020-11-02 11:08 -0600
        Re: Is bool no longer a primitive data type of C/C++ ? Bonita Montero <Bonita.Montero@gmail.com> - 2020-11-02 18:14 +0100
          Re: Is bool no longer a primitive data type of C/C++ ? olcott <NoOne@NoWhere.com> - 2020-11-02 12:17 -0600
            Re: Is bool no longer a primitive data type of C/C++ ? David Brown <david.brown@hesbynett.no> - 2020-11-02 22:41 +0100
    Re: Is bool no longer a primitive data type of C/C++ ? David Brown <david.brown@hesbynett.no> - 2020-11-02 22:48 +0100
      Re: Is bool no longer a primitive data type of C/C++ ? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-11-02 16:05 -0800
        Re: Is bool no longer a primitive data type of C/C++ ? olcott <NoOne@NoWhere.com> - 2020-11-02 18:45 -0600
        Re: Is bool no longer a primitive data type of C/C++ ? David Brown <david.brown@hesbynett.no> - 2020-11-03 11:35 +0100
  Why macro ? Bonita Montero <Bonita.Montero@gmail.com> - 2020-11-02 19:03 +0100
    Re: Why macro ? scott@slp53.sl.home (Scott Lurndal) - 2020-11-02 19:05 +0000
      Re: Why macro ? Bonita Montero <Bonita.Montero@gmail.com> - 2020-11-03 07:41 +0100
        Re: Why macro ? David Brown <david.brown@hesbynett.no> - 2020-11-03 11:38 +0100
          Re: Why macro ? Bonita Montero <Bonita.Montero@gmail.com> - 2020-11-03 12:39 +0100
            Re: Why macro ? David Brown <david.brown@hesbynett.no> - 2020-11-03 13:10 +0100
              Re: Why macro ? Bonita Montero <Bonita.Montero@gmail.com> - 2020-11-03 13:23 +0100
                Re: Why macro ? Bo Persson <bo@bo-persson.se> - 2020-11-03 13:45 +0100
                Re: Why macro ? Bonita Montero <Bonita.Montero@gmail.com> - 2020-11-03 14:26 +0100
                Re: Why macro ? Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2020-11-03 05:46 -0800
                Re: Why macro ? Bonita Montero <Bonita.Montero@gmail.com> - 2020-11-03 15:10 +0100
                Re: Why macro ? David Brown <david.brown@hesbynett.no> - 2020-11-03 15:49 +0100
                Re: Why macro ? Bonita Montero <Bonita.Montero@gmail.com> - 2020-11-03 15:56 +0100
                Re: Why macro ? David Brown <david.brown@hesbynett.no> - 2020-11-03 17:25 +0100
                Re: Why macro ? Bonita Montero <Bonita.Montero@gmail.com> - 2020-11-03 17:29 +0100
                Re: Why macro ? scott@slp53.sl.home (Scott Lurndal) - 2020-11-03 17:12 +0000
                Re: Why macro ? Bonita Montero <Bonita.Montero@gmail.com> - 2020-11-03 18:15 +0100
                Re: Why macro ? red floyd <no.spam.here@its.invalid> - 2020-11-04 07:12 -0800
                Re: Why macro ? Bonita Montero <Bonita.Montero@gmail.com> - 2020-11-04 16:33 +0100
                Re: Why macro ? Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2020-11-03 09:22 -0800
                Re: Why macro ? Bart <bc@freeuk.com> - 2020-11-03 17:13 +0000
                Re: Why macro ? David Brown <david.brown@hesbynett.no> - 2020-11-03 20:07 +0100
                Re: Why macro ? Juha Nieminen <nospam@thanks.invalid> - 2020-11-04 13:41 +0000
                Re: Why macro ? Juha Nieminen <nospam@thanks.invalid> - 2020-11-04 13:32 +0000
                Re: Why macro ? Richard Damon <Richard@Damon-Family.org> - 2020-11-04 08:59 -0500
                Re: Why macro ? Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2020-11-04 06:01 -0800
                Re: Why macro ? Sjouke Burry <burrynulnulfour@ppllaanneett.nnll> - 2020-11-04 17:11 +0100
                Re: Why macro ? Richard Damon <Richard@Damon-Family.org> - 2020-11-04 20:33 -0500
                Re: Why macro ? David Brown <david.brown@hesbynett.no> - 2020-11-04 16:44 +0100
                Re: Why macro ? Richard Damon <Richard@Damon-Family.org> - 2020-11-03 12:37 -0500
                Re: Why macro ? Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2020-11-03 10:42 -0800
                Re: Why macro ? scott@slp53.sl.home (Scott Lurndal) - 2020-11-03 19:43 +0000
                Re: Why macro ? David Brown <david.brown@hesbynett.no> - 2020-11-04 09:20 +0100
        Re: Why macro ? Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2020-11-03 03:07 -0800
          Re: Why macro ? Bonita Montero <Bonita.Montero@gmail.com> - 2020-11-03 12:40 +0100
            Re: Why macro ? Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2020-11-03 04:02 -0800
  Re: Is bool no longer a primitive data type of C/C++ ? megonsara11@gmail.com - 2020-11-06 20:37 -0800

csiph-web