Re: Representation of _Bool

Liste des GroupesRevenir à cl c 
Sujet : Re: Representation of _Bool
De : learningcpp1 (at) *nospam* gmail.com (m137)
Groupes : comp.lang.c
Date : 19. Jan 2025, 03:08:54
Autres entêtes
Organisation : novaBBS
Message-ID : <593ed9cd7fcf77cdef190bf8113d85e9@www.novabbs.com>
References : 1 2 3
User-Agent : Rocksolid Light
On Fri, 17 Jan 2025 4:40:16 +0000, Kaz Kylheku wrote:
On 2025-01-17, m137 <learningcpp1@gmail.com> wrote:
Hi Keith,
>
Thank you for posting this.
>
When, where? No attribution; referenced article is expired from this
Eternal September server, which has decently long retentation times.
>
Hi Kaz,
Sorry for the confusion, I am new to the platform and had not realised
that I needed to quote Keith's post in my text.

I noticed that the newer drafts of C23
(N2912 onwards, I think) have replaced the term "trap representation"
with "non-value representation":
>
That is correct. Probably because "trap representation" insinuates
that such a representation *must* produce a trap, or else the
implementation has no right to specify such a representation.
>
Impelmentations are not obliged to produce traps in relation to
non-value representations. Since the behaviors in question are
undefined, they may do so.
>
Thanks, I was wondering about this.

If so, what happens to the 254 trap representations that GCC and Clang
reserve for `_Bool`? Assuming a width of 1, each of those 254 object
>
GCC and Clang specifies trap representations for _Bool? Where is this
found in their documentation?
>
It is not documented (see this thread for GCC:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88662). But I think it can
be inferred from the code snippets in Keith's OP and most recent post.
GCC seems to treat all object representations of `_Bool` other than
0b00000000 and 0b00000001 as trap/non-value representations.
I am not sure about Clang, but compiling the last snippet in this
article:
https://www.trust-in-soft.com/resources/blogs/2016-06-16-trap-representations-and-padding-bits with
Clang 19.1.0 and options "-std=c23 -O3 -pedantic" seems to show that
Clang treats `_Bool` as having 254 non-value representations (see here:
https://gcc.godbolt.org/z/4jK9d69P8).

In an integer type, it is indeed possible for the padding bits to be
nonzero, without changing the value given by the value bits.
>
However, how that works is not specified; it's up to an implementation,
and doesn't have to be documented.
>
An implementation could say that the padding bits don't mean anything;
they can have any value whatsoever and so the situation is as you
say: the bool representations with a 0 in the value bit are all false,
and those with a 1 are all true.
>
However, an implementation can also say that certain patterns of
bits are non-value reprensentations.
>
One example given is the possibility of parity bits. Suppose some
integer type has one padding bit which behaves as a parity bit.  Then
suppose whenever that bit has incorrect parity, the representation is
deemed a non-value representation.
>
With regard to bool (say, one implemented in 8 bits), an impelmentation
can assert that if there is a nonzero value in any padding bit, the
result is a non-value representation. Then, only 0 and 1 are valid;
all other byte codes are non-value representations.
>
Implementations determine their own rules for how configurations of
padding bits may, on their own, or in interaction with configurations
of value bits, give rise to non-value representations.
Thank you, I really appreciate you taking the time to reply.
--

Date Sujet#  Auteur
17 Jan 25 * Re: Representation of _Bool15m137
17 Jan 25 +* Re: Representation of _Bool6Kaz Kylheku
17 Jan 25 i+- Re: Representation of _Bool1David Brown
17 Jan 25 i+- Eternal September server retention Was: Representation of _Bool1Michael S
17 Jan 25 i+- Re: Representation of _Bool1James Kuyper
19 Jan 25 i`* Re: Representation of _Bool2m137
19 Jan 25 i `- Re: Representation of _Bool1Keith Thompson
17 Jan 25 +* Re: Representation of _Bool3Tim Rentsch
19 Jan 25 i`* Re: Representation of _Bool2m137
19 Jan 25 i `- Re: Representation of _Bool1Tim Rentsch
17 Jan 25 `* Re: Representation of _Bool5Keith Thompson
18 Jan 25  +- Re: Representation of _Bool1Tim Rentsch
19 Jan 25  `* Re: Representation of _Bool3m137
19 Jan 25   `* Re: Representation of _Bool2Kenny McCormack
21 Jan 25    `- Re: Representation of _Bool1m137

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal