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


Groups > comp.lang.c > #161143

Re: Representation of _Bool

From Keith Thompson <Keith.S.Thompson+u@gmail.com>
Newsgroups comp.lang.c
Subject Re: Representation of _Bool
Date 2021-05-24 13:15 -0700
Organization None to speak of
Message-ID <87lf8351o0.fsf@nosuchdomain.example.com> (permalink)
References <87tums515a.fsf@nosuchdomain.example.com> <87wnromlnu.fsf@bsb.me.uk>

Show all headers | View raw


Ben Bacarisse <ben.usenet@bsb.me.uk> writes:
> Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
>> Conclusions:
>>
>> sizeof (_Bool) >= 1.  It may be greater than 1, but that would
>> be weird.  If sizeof (_Bool) > 1, then it must have padding bits.
>
> I don't understand how you draw that last conclusion.

[answered elsethread]

> <cut>
>> Here's a small program that attempts to explore how an implementation
>> represents objects of type _Bool:
>>
>> #include <stdio.h>
>> #include <limits.h>
>>
>> union U {
>>     _Bool b;
>>     unsigned char rep;
>> };
>
> When doing this kind of thing, my preference is to write
>
>   union U {
>       _Bool b;
>       unsigned char rep[sizeof (_Bool)];
>   };
>
> even when it's very unlikely that the size will be > 1.  It makes the
> purpose so very clear.

Good point.

-- 
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


Thread

Representation of _Bool Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2021-05-23 19:14 -0700
  Re: Representation of _Bool Philipp Klaus Krause <pkk@spth.de> - 2021-05-25 11:40 +0200
  Re: Representation of _Bool Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-05-24 12:11 +0100
    Re: Representation of _Bool Richard Damon <Richard@Damon-Family.org> - 2021-05-24 07:43 -0400
      Re: Representation of _Bool Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-05-24 17:27 +0100
      Re: Representation of _Bool Vir Campestris <vir.campestris@invalid.invalid> - 2021-05-25 21:20 +0100
    Re: Representation of _Bool Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2021-05-24 13:15 -0700
  Re: Representation of _Bool Tim Rentsch <tr.17687@z991.linuxsc.com> - 2021-05-24 06:49 -0700
    Re: Representation of _Bool Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2021-05-24 13:30 -0700
  Re: Representation of _Bool jacobnavia <jacob@jacob.remcomp.fr> - 2021-05-24 18:40 +0200
    Re: Representation of _Bool David Brown <david.brown@hesbynett.no> - 2021-05-24 18:55 +0200
    Re: Representation of _Bool Bart <bc@freeuk.com> - 2021-05-24 18:31 +0100

csiph-web