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

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

Re: [avr-gcc-list] Function specific volatile


From: Dmitry K.
Subject: Re: [avr-gcc-list] Function specific volatile
Date: Mon, 28 Apr 2003 09:28:36 +1100
User-agent: KMail/1.4.3

27 Apr 2003 07:06 Anton Erasmus:
> On 03/04/26 at 01:08 Mark Williams (MWP) wrote:
> >Hi all...
> >
> >Is there a way to force a global non-volatile var to be considered
> >volatile in a specific function (int handler)?
> >
> >This would be handy for variables that are only read in int handlers.
> >
> >Thanks,
> >Mark.
>
> Just do a cast.
>
> int foo;
>
> void Intfunc(void)
> {
>   int i;
>
>   i=(volatile int)foo;
> }
>
>
> Regards
>   Anton Erasmus

------------------------------------------------------------------
No, true is:
        * (volatile int *) &foo
------------------------------------------------------------------

extern int foo;

int fun1 (void)
{
    foo = 0;
    return (volatile int) foo;          // no reading from foo
}

int fun2 (void)
{
    foo = 0;
    return *(volatile int*) &foo;       // yes, reading
}

Result:

   3:ext_volatile.c **** int fun1 (void)
   4:ext_volatile.c **** {
  41                    .LM1:
  42                    /* prologue: frame size=0 */
  43                    /* prologue end (size=0) */
   5:ext_volatile.c ****     foo = 0;
  45                    .LM2:
  46 0000 1092 0000             sts (foo)+1,__zero_reg__
  47 0004 1092 0000             sts foo,__zero_reg__
   6:ext_volatile.c ****     return (volatile int) foo;
   7:ext_volatile.c **** }
  49                    .LM3:
  50 0008 80E0                  ldi r24,lo8(0)
  51 000a 90E0                  ldi r25,hi8(0)
  52                    /* epilogue: frame size=0 */
  53 000c 0895                  ret

   9:ext_volatile.c **** int fun2 (void)
  10:ext_volatile.c **** {
  64                    .LM4:
  65                    /* prologue: frame size=0 */
  66                    /* prologue end (size=0) */
  11:ext_volatile.c ****     foo = 0;
  68                    .LM5:
  69 000e 1092 0000             sts (foo)+1,__zero_reg__
  70 0012 1092 0000             sts foo,__zero_reg__
  12:ext_volatile.c ****     return *(volatile int*) &foo;
  72                    .LM6:
  73 0016 8091 0000             lds r24,foo
  74 001a 9091 0000             lds r25,(foo)+1
  13:ext_volatile.c **** }
  76                    .LM7:
  77                    /* epilogue: frame size=0 */
  78 001e 0895                  ret

Regards.



reply via email to

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