avr-gcc-list
[Top][All Lists]
Advanced

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

Re: [avr-gcc-list] C coding question


From: Tom Deutschman
Subject: Re: [avr-gcc-list] C coding question
Date: Fri, 6 Oct 2006 06:16:44 -0700

I agree with Nigel, but yes, (!0 == 1).

Quoted from C Programming Language Reference Manual section A7.4.7
The operand of the ! operator must have arithmetic type or be a pointer, and the result is 1 if the value of its operand compares equal to 0, and 0 otherwise. The type of the result is int.


Try it yourself, it's the second best way to answer a question like this.

int main(void)
{
int8_t i8;
int i;
uint8_t u8;
uint16_t u16;

i8 = (!0); /* i8 == 0x01 */
i = (!0); /* i == 0x0001 */
u8 = (!0); /* u8 == 0x01 */
u16 = (!0); /* u16 == 0x0001 */
}


I have seen TRUE and FALSE defined this way before:

#if !defined( TRUE )
#define TRUE !FALSE
#define FALSE 0
#endif /* !TRUE */

Here are the results from Google Code Search with "#define TRUE !FALSE" search terms:
http://www.google.com/codesearch?hl=en&lr=&q=%23define+TRUE+%21FALSE&btnG=Search

Tom



On 10/6/06, Nigel Winterbottom <address@hidden> wrote:


> -----Original Message-----
> From: larry barello

> Specifically I was looking for an efficient way to encode
>
> (bSomeBool ^ (SomeBitMask & SomeVariable))
>
> to get a true/false output.

Does it have to be an _expression_ ?

If not, what's wrong with:

if (SomeBitMask & SomeVariable)
    bSomeBool = !bSomeBool;

Nigel



_______________________________________________
AVR-GCC-list mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list



--
--
Tom Deutschman
Wizbang Designs, Inc.
1217 S. Oak St.
Spokane, WA  99204
(509) 251-1106
reply via email to

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