[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: [avr-gcc-list] Comma Operator in #define
From: |
Tom Harris |
Subject: |
RE: [avr-gcc-list] Comma Operator in #define |
Date: |
Wed, 23 Jul 2003 10:07:34 +1000 |
I think that commas only seperates expressions, which are evaluated and the
result is the result of the last expression, so that
a = ++b, c;
sets a to the value of c, after incrementing b. I have never seen the point
of using it, it seems to lead to hard to understand code.
The `asm` is a statement, not an expression, so it must be terminated by a
semicolon.
Why not define an inline function for your code? It will have the same
effect as a #define, but be safer.
(in a header file):
extern inline void set_clock(uint8_t x) {
asm volatile("nop\n\t"::);
PORTB |= BIT3;
}
TomH <tomh(AT)optiscan(DOT)com>
-----Original Message-----
From: Keith Gudger [mailto:address@hidden
Sent: Wednesday, 23 July 2003 7:58 AM
To: E. Weddington
Cc: address@hidden
Subject: Re: [avr-gcc-list] Comma Operator in #define
Eric:
PLease check your ANSI C manual - a 'comma' operator is a perfectly legal
C operator for separating 'C' statements. It should work in a define if
the pre-processor is working correctly.
Keith
On Tue, 22 Jul 2003, E. Weddington wrote:
> > Maybe I'm missing something, but I *did* check the ANSI C
> manual, and this
> > should be OK, I think.
> >
> > I want to use a comma operator in a macro (#define)
> statement:
> >
> > #define set_clock(x) asm volatile("nop\n\t"::), (PORTB |=
> BIT3)
> >
> > avr-gcc gives the following error when I use this macro:
> >
> > set_clock();
> >
> > error: parse error before ',' token
> >
> > If I just make it a ';', then everything works OK.
> >
> > Any ideas? What am I doing wrong? Or is this a bug?
> >
>
> AFAIK, the define body is composed of 2 seperate C
> statements which should be seperated by semicolon. A comma
> does not seperate C statements; a semicolon seperates C
> statements. (Sometimes in English too. ;-))
>
> It's not a matter of whether a comma is allowed in macro,
> as so much whether the macro is defined to be legal C.
>
>
>
>
>
_______________________________________________
avr-gcc-list mailing list
address@hidden
http://www.avr1.org/mailman/listinfo/avr-gcc-list