[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Discuss-gnuradio] Regarding gr_squelch_base_cc.cc
From: |
Marcus D. Leech |
Subject: |
Re: [Discuss-gnuradio] Regarding gr_squelch_base_cc.cc |
Date: |
Thu, 29 Apr 2010 10:33:44 -0400 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.9) Gecko/20100330 Fedora/3.0.4-1.fc12 Thunderbird/3.0.4 |
On 04/29/2010 04:55 AM, Mattias Kjellsson wrote:
>
> 61:
> 62: case ST_UNMUTED:
> 63: if (mute())
> 64: d_state = d_ramp ? ST_DECAY : ST_MUTED; // If not ramping,
> go straight to muted
> 65: break;
>
> It might be that I don't fully understand the "?"- construct, but if I
> try to translate line 64 into an if- statement, I would do it (with my
> understanding) to something like:
>
> if(d_state = d_ramp){
> d_state = ST_DECAY;
> }
> else{
> d_state = ST_MUTED;
> }
>
> But this can't be the way since this will always set d_state =
> ST_DECAY (?) Or it could be the way, but in that case... Why the crazy
> ?- construct?
>
> As I said earlier, I'm scared and confused, since the code does it's
> job but it looks very... Suspicious
>
> BR
> Mattias
>
>
>
Ah, conditional expressions.
Let's deal with line 64:
d_state = d_ramp ? ST_DECAY : ST_MUTED; // If not ramping, go
straight to muted
Translated into "conventional" conditionals:
if (d_ramp != 0)
{
d_state = ST_DECAY;
}
else
{
d_state = ST_MUTED;
}
In C, you can have a condition expression that just mentions the
variable name, without any explicit
comparision operator:
if (foo)
{
...
}
Which in another language would be:
if (foo not-equal 0)
{
}
So, the "?" operator isn't all that crazy after all:
(condition) ? (clause-to-execute-if-true) : (clause-to-execute-if-false)
--
Marcus Leech
Principal Investigator
Shirleys Bay Radio Astronomy Consortium
http://www.sbrac.org