[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[avr-gcc-list] C coding question

From: larry barello
Subject: [avr-gcc-list] C coding question
Date: Thu, 5 Oct 2006 15:04:03 -0700

when mixing bit-wise and logical operations, is it safe to assume that (!0
== 1) is true?

Specifically I was looking for an efficient way to encode

(bSomeBool ^ (SomeBitMask & SomeVariable)) 

to get a true/false output.  Of course, expressed, as above, doesn't work
too well when bit-wise exclusive or-ing the bool with the bitmask.

So I said:

(bSomeBool?1:0) ^ ((SomeBitMask & SomeVariable)?1:0))

which worked fine, but isn't particularly efficient in assembly. Not that I
really care, but since I had to look at it to realize my mistake, I became
interested in a better way to express the thought.  For example, is the
following guaranteed to work?

(bSomeBool ^ ((SomeBitMask & SomeVariable)?1:0))

Where bSomeBool is either 0 or !0?


reply via email to

[Prev in Thread] Current Thread [Next in Thread]