?

Log in

No account? Create an account
Off in the distance
browse
my journal
links
May 2016
 

The Bellinghman
Date: 2008-01-24 12:07
Subject: Coding oddities
Security: Public
I'm amused by the statement below.

bool
foo(bool &SelectionChanged, .....)
{
   .....
   SelectionChanged |= true;
   .....
}
Post A Comment | 3 Comments | | Flag | Link



Ian
User: liasbluestone
Date: 2008-01-24 12:10 (UTC)
Subject: (no subject)
Is it there to stop the compiler whinging about SelectionChanged being defined but not used? The optimiser should just ignore it anyway.
Reply | Thread | Link



Ian
User: liasbluestone
Date: 2008-01-24 12:13 (UTC)
Subject: (no subject)
No, ignore me, I'm being stupid.

It's the same as

SelectionChanged = true;

not

SelectionChanged = SelectionChanged;
Reply | Parent | Thread | Link



The Bellinghman
User: bellinghman
Date: 2008-01-24 12:18 (UTC)
Subject: (no subject)
Exactly. I hope the optimiser does optimise out the read of the variable, but it's not as though one extra read is going to make the damnedest bit of difference anyway.

Which is why I'm amused - it's a code construct that does the right thing, but is slightly less efficient than the obvious one. It's conceivable it's a typo - a harmless one, for once.

Oh, and using bit-wise logic on bools? Well, given the continuing non-existence of &&= and ||=, I suppose there are occasions when you have to, but it gives me a nasty feeling in my mouth.
Reply | Parent | Thread | Link