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

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

Re: [avr-gcc-list] generic queue library for AVR GCC?


From: Dave Hansen
Subject: Re: [avr-gcc-list] generic queue library for AVR GCC?
Date: Wed, 17 Nov 2004 14:46:54 -0500

From: Andy Warner <address@hidden>

Bruce D. Lightner wrote:
[...]
>       #define begin_critical_section()  SREG, cli()
>       #define end_critical_section(val) SREG = val
>       ....
>       {
>           unsigned char sreg = begin_critical_section();

Is that going to work the way you expect it to ?

I don't think so.

But

  unsigned char sreg;
  sreg = begin_critical_section();

should definitely work.


I understood that the comma operator returns the type and
value of the rightmost statement (which will be cli()
in this example.)

But the comma operator has lower precedence than the assignment operator. So

  sreg = SREG, cli();

should parse as

  (sreg = SREG), (cli());

Which is why I question the original code, which mixes in a declaration. The = in the declaration is not an assignment operator, so I suspect that will parse as

  unsigned char sreg = (SREG, cli());

as you suggest.

Regards,
  -=Dave




reply via email to

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