>
> 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
_______________________________________________
Discuss-gnuradio mailing list
Discuss-gnuradio@gnu.org
http://lists.gnu.org/mailman/listinfo/discuss-gnuradio
No comments:
Post a Comment