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

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

Re: [avr-gcc-list] possible compiler/optimizer problem (?)


From: Radu Ciurlea
Subject: Re: [avr-gcc-list] possible compiler/optimizer problem (?)
Date: Mon, 30 May 2005 21:11:53 +0300
User-agent: Mozilla Thunderbird 1.0.2 (Windows/20050317)

You problem is you are using plain wrong C syntax. `value!=value' is an expression, not an assignment. It basically says `value is not equal to value'. This is not quite useful since it will always evaluate to false and do nothing else. However, if you write `value = !value' you change `value' to true (1) if it was false (0) and change it to false if it was true. So the difference is pretty huge.
Cheers,

Radu Ciurlea
radu at ploiesti dot roedu dot net

Gary Douglas wrote:
Hi all,

Not sure if this is a bug, or if what I'm trying to do is just incorrect C syntax. Regardless, the compiler doesn't warn about the following:

void led_blinky()
{
    static uint8_t value= 1;
value != value;//This is the problem line - always true if(value)
    {
        PORTD &= ~(1<<7);
    }
    else
    {
        PORTD |= (1<<7);
    }
}

If I change it to this it works:

void led_blinky()
{
    static uint8_t value= 1;
    value = (!value); //This works...
    if(value)
    {
        PORTD &= ~(1<<7);
    }
    else
    {
        PORTD |= (1<<7);
    }
}

Are these not fundamentally the same?

FYI: Using avr-gcc 3.4.3 on FC1 Linux.
Configured with: ../../source/gcc-3.4.3/configure -v --target=avr --disable-nls --prefix=/tools/avr --with-gnu-ld --with-gnu-as --enable-languages=c,c++ --quiet --with-dwarf2
Thread model: single
gcc version 3.4.3

Regards,

Gary Douglas







reply via email to

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