TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: VADIM DAVYDOFF
from: THOMAS MAEDER
date: 1997-07-20 13:15:00
subject: Classes

VD> I'd write instead:
VD> void MouseInfo::setButtons(int but)
VD> {
VD>     installed = (buttons = but) + 1 ? False : True;
VD> }
I wouldn't.
Not only is the "installed" member variable redundant, as I wrote here
some time ago, but I also think that your proposal is very bad style:
- use operator! instead of ?: (?: is ok, but not here):
installed = !((buttons = but) + 1);
- if comparing against -1, say so:
installed = (buttons = but) != -1;
- don't use the result of an assignment like this (any decent compiler
is right to issue a warning):
buttons = but;
installed = buttons!=-1;
Now  the code looks like what a human (me!) thinks when writing it. On
a compiler worth its  money,  the  resulting  object  code  should  be
exactly the same (if False and True are reasonably defined).
Thomas
---
 þ MM 1.0 #0113 þ When you don't know what you're doing, do it neatly
---------------
* Origin: McMeier & Son BBS (2:301/138)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.