2004-01-05 01:38:58

by Måns Rullgård

[permalink] [raw]
Subject: Re: GCC 3.4 Heads-up

Bill Davidsen <[email protected]> writes:

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

What's wrong with

d = long_expression;
if (a)
b = d;
else
c = d;

Your long expression is still only in one place.

--
M?ns Rullg?rd
[email protected]


2004-01-05 23:58:29

by Ingo Oeser

[permalink] [raw]
Subject: Re: GCC 3.4 Heads-up

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Monday 05 January 2004 02:38, M?ns Rullg?rd wrote:
> What's wrong with
>
> d = long_expression;
> if (a)
> b = d;
> else
> c = d;
>
> Your long expression is still only in one place.

This seperates control and data flow quite nicely, which is good
programming practise anyway and helps the compiler optimizing, AFAIK.

Regards

Ingo Oeser

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)

iD8DBQE/+fgMU56oYWuOrkARAlOIAJ0c9QMsQRrXYv3RIV3r+8uAnJgETQCfQ7PJ
Zscp0VfGY2jS1RvWnuCAqoc=
=kY28
-----END PGP SIGNATURE-----