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

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

Re: [avr-gcc-list] volatile bug in GCC?


From: Brian Dean
Subject: Re: [avr-gcc-list] volatile bug in GCC?
Date: Sun, 11 Aug 2002 21:42:20 -0400
User-agent: Mutt/1.4i

The placement of volatile is not correct for the behaviour you want.
If you want a volatile pointer, place volatile after the '*', i.e.:

        char * volatile ptr;

The way you have it below, you've declared a pointer to volatile data.
The difference is somewhat subtle.

-Brian


On Mon, Aug 12, 2002 at 03:37:50AM +0300, Janne Heikkinen wrote:
> Date: Mon, 12 Aug 2002 03:37:50 +0300
> From: Janne Heikkinen <address@hidden>
> To: address@hidden
> Subject: [avr-gcc-list] volatile bug in GCC?
> Precedence: bulk
> X-UIDL: 2b6e1adb1d32583bebc69a7a072b10f6
> 
> 
> Following code produces weird behaviour when compiled with
> GCC 3.1.1 or 3.3:
> 
> #include <stdlib.h>
> 
> volatile char *ptr=NULL;
> 
> volatile int i=0;
> 
> main()
> {
>     while(i);
> 
>     while(ptr);
> }
> 
> After compiling with:
> 
> avr-gcc -mmcu=at90s8515 -Os -S t.c
> 
> and looking at t.s:
> 
> main:
> /* prologue: frame size=0 */
>         ldi r28,lo8(__stack - 0)
>         ldi r29,hi8(__stack - 0)
>         out __SP_H__,r29
>         out __SP_L__,r28
> /* prologue end (size=4) */
> .L2:
>         lds r24,i
>         lds r25,(i)+1
>         or r24,r25
>         brne .L2
>         lds r24,ptr
>         lds r25,(ptr)+1
> .L5:
>         sbiw r24,0
>         brne .L5
> /* epilogue: frame size=0 */
>         rjmp exit
> 
> First it won't reload ptr like it should  and second it won't check
> it's value properly.
> 
> Janne Heikkinen
> 
> avr-gcc-list at http://avr1.org
avr-gcc-list at http://avr1.org



reply via email to

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