as 7 Apr 2004 03:33 Sergei Sharonov wrote:
>
> -------------------
> volatile short *pbuf, *plast;
>
> int main(void)
> {
> short buf[10];
> pbuf = buf;
> plast = buf + 10;
> while(pbuf < plast);
> return 0;
> }
>
> void foo(void) /* called from interrupt */
> {
> if(pbuf <= plast) *pbuf++ = 0;
> }
>
> -----------
> Compiles into:
>
> while(pbuf < plast);
> 4054: 0f 9e cmp r14, r15 ;
> 4056: fe 2b jnc $-2 ;abs 0x4054
>
> > 2. volatile var updates every time after 'volatile value' updated.
>
> See above.
>
Compiler is right.
Variables in buf[10] are volatiles in this example.
Try another place of word `volatile':
short * volatile pbuf, * volatile plast;
Now volatiles are pointers:
.L2:
mov &pbuf, r14
mov &plast, r15
cmp r15, r14
jlo .L2
Best regards.