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: Theodore A. Roth
Subject: Re: [avr-gcc-list] generic queue library for AVR GCC?
Date: Wed, 17 Nov 2004 11:47:43 -0800 (PST)

On Wed, 17 Nov 2004 address@hidden wrote:

> Bruce is beating that poor dead horse with a wet noodle. ;)

Let's please not degenerate this discussion even if it is a dead horse.

Bruce is actually correct. [See below.]

>    Bruce D. Lightner wrote:
>    > [...]
>    > You all of course know that "," can be used in place of ";" to
>    > separate C statements.  Therefore we can make a minor change to
>    > the first macro definition...
>    > [...]
>    >       #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 understood that the comma operator returns the type and
>    value of the rightmost statement (which will be cli()
>    in this example.)

You are partially correct.

Here's a simple program that shows that the right thing is done:

#include <stdio.h>
int get_a (void) { return 'A'; }
int get_b (void) { return 'B'; }

int main (void)
{
        int ch;

        if (get_a () == 'A') ch = get_a (), get_b ();
        printf ("ch = %c\n", ch);

        ch = get_a (), get_b ();
        printf ("ch = %c\n", ch);

        ch = ( get_a (), get_b () );
        printf ("ch = %c\n", ch);

        return 0;
}

Compiling that on linux and running it yields:

address@hidden:~$ ./foo
ch = A
ch = A
ch = B

---
Ted Roth
PGP Key ID: 0x18F846E9
Jabber ID: address@hidden


reply via email to

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