From: Bill Davidsen <davidsen@tmr.com>
To: Linus Torvalds <torvalds@osdl.org>
Cc: Krzysztof Halasa <khc@pm.waw.pl>, linux-kernel@vger.kernel.org
Subject: Re: GCC 3.4 Heads-up
Date: Sun, 04 Jan 2004 20:28:27 -0500 [thread overview]
Message-ID: <3FF8BDBB.4060708@tmr.com> (raw)
In-Reply-To: <Pine.LNX.4.58.0401041232440.2162@home.osdl.org>
Linus Torvalds wrote:
>
> On Sun, 4 Jan 2004, Bill Davidsen wrote:
>
>>Since that's a matter of taste I can't disagree. The point was that the
>>original post used
>> *(a ? &b : &c) = d;
>>which generates either warnings or errors if b or c is a register
>>variable, because you are not allowed to take the address of a register.
>
>
> The thing is, the above case is the _only_ case where there is any point
> to using a conditional expression and an assignment to the result in the
> same expression.
We disagree, see below.
> If you have local variables (register or not), the sane thing to do is
>
> if (a)
> b = d;
> else
> c = d;
>
> or variations on that. That's the readable code.
But may lead to errors in maintenence. Your first example below avoids
that problem. Imagine instead of "d" you have a 40-50 character RHS. Now
imagine that the code needs to be changed. If you have the long
expression in two places then it invites the possiblility of someone
changing only one of them. You may never make mistakes, but the rest of
us do, and the conditional LHS avoids that.
>
> The only case where conditional assignment expressions are useful is when
> you are literally trying to avoid doing branches, and the compiler isn't
> smart enough to avoid them otherwise.
>
> Check the compiler output some day. Try out what
>
> int a, b;
>
> void test_assignment_1(int val)
> {
> *(val ? &a : &b) = 1;
> }
You pointed out that this generates good code, I pointed out that it
also avoids future errors and is not just a trick for broken compilers.
I take your point about generating good code, I'm sorry you can't see
that avoiding code duplication is good practice even without the benefit
of better code.
--
bill davidsen <davidsen@tmr.com>
CTO TMR Associates, Inc
Doing interesting things with small computers since 1979
next prev parent reply other threads:[~2004-01-05 1:28 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-12-26 1:46 GCC 3.4 Heads-up Chris Meadors
2003-12-26 3:46 ` H. Peter Anvin
2003-12-26 4:34 ` Linus Torvalds
2003-12-26 6:04 ` H. Peter Anvin
2003-12-26 6:58 ` Andy Isaacson
2003-12-26 7:07 ` H. Peter Anvin
2003-12-26 7:08 ` Linus Torvalds
2003-12-29 16:13 ` David Lloyd
2004-01-02 21:57 ` Bill Davidsen
2004-01-03 21:11 ` Krzysztof Halasa
2004-01-04 5:48 ` Bill Davidsen
2004-01-04 20:41 ` Linus Torvalds
2004-01-05 1:28 ` Bill Davidsen [this message]
2004-01-05 1:38 ` Måns Rullgård
2004-01-05 23:49 ` Ingo Oeser
2004-01-05 2:25 ` Linus Torvalds
2004-01-05 4:15 ` Bill Davidsen
2004-01-05 4:36 ` Linus Torvalds
2003-12-30 1:37 ` Rusty Russell
-- strict thread matches above, loose matches on Subject: below --
2003-12-26 11:02 linux
2003-12-26 20:05 ` Linus Torvalds
2003-12-27 16:39 ` Andreas Schwab
[not found] <16PqK-8eK-1@gated-at.bofh.it>
[not found] ` <16RiU-2kO-1@gated-at.bofh.it>
[not found] ` <16S5h-3no-5@gated-at.bofh.it>
2004-01-06 21:06 ` David Mosberger-Tang
2004-01-06 22:33 ` Richard Henderson
2004-01-06 23:23 ` Linus Torvalds
2004-01-07 9:54 ` Richard Henderson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3FF8BDBB.4060708@tmr.com \
--to=davidsen@tmr.com \
--cc=khc@pm.waw.pl \
--cc=linux-kernel@vger.kernel.org \
--cc=torvalds@osdl.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.