> -----Original Message----- > From: > [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] > org] On Behalf Of Paulo Marques > Sent: Monday, October 09, 2006 4:39 AM > To: larry barello > Cc: avr-gcc-list@nongnu.org > Subject: Re: [avr-gcc-list] C coding question > > larry barello wrote: > > [...] > > So I said: > > > > (bSomeBool?1:0) ^ ((SomeBitMask & SomeVariable)?1:0)) > > Since no one else made this comment, I just wanted to point > out that you > can write that as: > > (bSomeBool ^ (!!(SomeBitMask & SomeVariable))) > > "!!" is often used to convert an integer value into a logical (0/1) > value. Maybe it is easier to the compiler than "?1:0".
I would question the "often used" phrase; this is the first I've heard of it in 15 years of programming in C. If you want a logical (boolean) XOR operation, you can write the expression simply: #include <stdbool.h> ... (bool)(bSomeBool != (bool)(SomeBitMask & SomeVariable)) Remember that the type of an equality/non-equality operator is another boolean value. Be sure to typecast the bitwise and operation to a bool value so the != operator is comparing values of the same type. _______________________________________________ AVR-GCC-list mailing list AVR-GCC-list@nongnu.org http://lists.nongnu.org/mailman/listinfo/avr-gcc-list