Deutsch English Français Italiano |
<v93hgg$9q8p$1@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!weretis.net!feeder8.news.weretis.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: James Kuyper <jameskuyper@alumni.caltech.edu> Newsgroups: comp.lang.c Subject: Re: how cast works? Date: Thu, 8 Aug 2024 18:40:15 -0400 Organization: A noiseless patient Spider Lines: 27 Message-ID: <v93hgg$9q8p$1@dont-email.me> References: <v8vlo9$2oc1v$1@dont-email.me> <87frrg9jud.fsf@nosuchdomain.example.com> <v92aha$3u7l7$2@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Injection-Date: Fri, 09 Aug 2024 00:40:16 +0200 (CEST) Injection-Info: dont-email.me; posting-host="ab5add5a204e6155067e82be1eb57cd0"; logging-data="321817"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+0i0SLBVjG2D5xyedvbc8uIdW+MomqoHY=" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:wuseoFP4+XOGsqnm+v8ofuEg7tM= Content-Language: en-US In-Reply-To: <v92aha$3u7l7$2@dont-email.me> Bytes: 2213 Thiago Adams <thiago.adams@gmail.com> writes: .... > I also curious about how bool works. > > Values converted to bool became 0 or 1. > When this conversion happens, at read or write? Both? You can take a value obtained by reading an object, or a value produced by evaluating an expression, and convert that value to a different type. That value can later be stored in an object, or it could be used as one of the operands for an expression. The conversion isn't associated with either the read or the write. Many conversions occur implicitly, a cast is used to explicitly make a conversion occur. int x = 3; bool b = x; In the above code, an implicit conversion from int to bool occurs after reading the value of 3 from x, and occurs before writing to bool. b = !(bool)(x-3); In this code, the conversion occurs after the value of 3 is retrieved from x, and after 3 is subtracted from it. That result of 0 is then converted to bool, and then the ! operator is applied to it. Finally, the result is written to b. So you see, it doesn't make sense to connect the conversion with either the read or the write.