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

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

Re: [avr-gcc-list] Comma Operator in #define


From: Joerg Wunsch
Subject: Re: [avr-gcc-list] Comma Operator in #define
Date: Wed, 23 Jul 2003 10:25:15 +0200 (MET DST)

As Tom Harris <address@hidden> wrote:

>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.

One of the most obvious reasons to use it is inside a for statement:

for (i = 0, cp = NULL; *cp; i++, cp++) { ... }

Semantically, you just don't care about the resulting value of the
expression in that case.  Syntactically, there must be exactly three
statements within the for statement's control expression, so the
comma is the way out.

There might be further points of using it, but you're right, they
often give hard to understand code.  In Keith's case, i don't see the
point however, since i doubt he's intending to use the final resulting
value of PORTB afterwards.

>The `asm` is a statement, not an expression, so it must be terminated
>by a semicolon.

This i agree.

Keith, remember the usual syntactical construct to glue multiple
expressions together as a single one is

#define foo(p) do {\
        mumble; \
        bar(p); \
} while (0)

-- 
J"org Wunsch                                           Unix support engineer
address@hidden        http://www.interface-systems.de/~j/


reply via email to

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