[sdiy] Quick C query
Scott Gravenhorst
music.maker at gte.net
Sun Nov 21 18:23:27 CET 2010
Tom Wiltshire <tom at electricdruid.net> wrote:
>
>On 21 Nov 2010, at 18:05, Steff wrote:
>
>> On 21 November 2010 17:45, cheater cheater <cheater00 at gmail.com> wrote:
>>>
>>>> if(flags == (BLARP | BAR)) { /* do stuff here */ }
>>>
>>> I think you mean:
>>>
>>> if(flags & (A | B) == (A | B)) {
>>> ...
>>> }
>
>I've seen this written as:
>
> if (flags & (A | B)) {
> ...
> }
>
>Which would be the following for a single flag:
>
> if (flags & mask) {
> ...
> }
>
>There's no need for the part with the "==(etc)", since C is just
>looking for a non-zero result to indicate true (simply processor
>zero flag clear, I hope).
>
>Or have I got the stick by the sticky end?
Looks correct to me. I use that kind of structure regulary in C (that is, "if"
statements without any comparison operator).
-- ScottG
________________________________________________________________________
-- Scott Gravenhorst
-- FPGA MIDI Synthesizer Information: home1.gte.net/res0658s/FPGA_synth/
-- FatMan: home1.gte.net/res0658s/fatman/
-- NonFatMan: home1.gte.net/res0658s/electronics/
-- When the going gets tough, the tough use the command line.
More information about the Synth-diy
mailing list