Warning: mysqli::__construct(): (HY000/1203): User howardkn already has more than 'max_user_connections' active connections in D:\Inetpub\vhosts\howardknight.net\al.howardknight.net\includes\artfuncs.php on line 21
Failed to connect to MySQL: (1203) User howardkn already has more than 'max_user_connections' active connections
Warning: mysqli::query(): Couldn't fetch mysqli in D:\Inetpub\vhosts\howardknight.net\al.howardknight.net\index.php on line 66
Article <86bk1yk35e.fsf@linuxsc.com>
Deutsch   English   Français   Italiano  
<86bk1yk35e.fsf@linuxsc.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: Tim Rentsch <tr.17687@z991.linuxsc.com>
Newsgroups: comp.lang.c
Subject: Re: how cast works?
Date: Sun, 11 Aug 2024 17:15:09 -0700
Organization: A noiseless patient Spider
Lines: 42
Message-ID: <86bk1yk35e.fsf@linuxsc.com>
References: <v8vlo9$2oc1v$1@dont-email.me> <87frrg9jud.fsf@nosuchdomain.example.com> <v92aha$3u7l7$2@dont-email.me> <v93hgg$9q8p$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Date: Mon, 12 Aug 2024 02:15:09 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="f42e4005105099d89c60a754521770ce";
	logging-data="3093877"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX18Oy5c/A+g5LhIQfoIffsy6Nw+3THtdtvw="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:MIwIybOsjUd6SjDNpglrQCydL5s=
	sha1:qqPFReikfxXr2r+xUvEHPscmxg4=
Bytes: 2670

James Kuyper <jameskuyper@alumni.caltech.edu> writes:

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

The assignment statement

    b = !(bool)(x-3);

performs two conversions.  The (bool) cast converts an int value
to a bool value.  The assignment to b converts the value of the !
subexpression (which is of type int) to bool before assigning it.

Assignment operators always convert the value being assigned to
the type of the assignment expression, even if the two types
are the same.