Deutsch English Français Italiano |
<87frre8v5q.fsf@nosuchdomain.example.com> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson <Keith.S.Thompson+u@gmail.com> Newsgroups: comp.lang.c Subject: Re: how cast works? Date: Thu, 08 Aug 2024 16:14:09 -0700 Organization: None to speak of Lines: 44 Message-ID: <87frre8v5q.fsf@nosuchdomain.example.com> References: <v8vlo9$2oc1v$1@dont-email.me> <slrnvb7kis.28a.dan@djph.net> <v929ah$3u7l7$1@dont-email.me> <v92gt1$e1l$1@dont-email.me> <20240808193203.00006287@yahoo.com> <v92va5$4msg$1@dont-email.me> <v9310a$4v1a$2@dont-email.me> <v93565$6ffo$1@dont-email.me> <v93h12$9vom$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain Injection-Date: Fri, 09 Aug 2024 01:14:10 +0200 (CEST) Injection-Info: dont-email.me; posting-host="153d1bcdb0929153f62e0b2f2aa4005b"; logging-data="330861"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19P0uKb6FwRQeaUUcZ5oX7H" User-Agent: Gnus/5.13 (Gnus v5.13) Cancel-Lock: sha1:RTz26HxHENDl2afsmvxWlYFj9qY= sha1:nXYBa8PnXZ4Toq14SQQsszpW16I= Bytes: 2936 David Brown <david.brown@hesbynett.no> writes: [...] > A _Bool is always either 0 or 1. The conversion is whatever the > compiler needs to give an int of value 0 or 1. The value of a _Bool object is always either 0 or 1 *unless* the program does something weird. C23 is a bit clearer about the representation of bool (still also called _Bool) than previous editions. It states (draft N3220) that : The type bool shall have one value bit and (sizeof(bool)*CHAR_BIT)-1 padding bits. There are several ways to force a representation other than 00000000 or 00000001 into a _Bool object, including a union, memset(), or type punning via a pointer cast. C23 dropped the term "trap representation", replacing it with "non-value representation" -- a reasonable change, since accessing a trap representation is not guaranteed to cause the program to "perform a trap" (defined as "interrupt execution of the program such that no further operations are performed"). It doesn't specify whether setting the padding bits to 1 results in a non-value representation. If non-zero padding bits create a non-value representation, then accessing a bool object holding such a representation has undefined behavior. It could, among other things, yield the same value implied by the representation as if it were an ordinary integer of the same size. If there are no non-value representations, then only the single value bit determines the value, which is either false or true. As you mentioned, I expect that sizeof (bool) will normally be 1, but an implementation could make it wider, e.g. with 1 value bit and 31 padding bits. [...] -- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com void Void(void) { Void(); } /* The recursive call of the void */