avr-libc-dev
[Top][All Lists]
Advanced

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

Re: [avr-libc-dev] Deprecation policy [was: Re: [RFC][PATCH] Deprecate


From: Dmitry K.
Subject: Re: [avr-libc-dev] Deprecation policy [was: Re: [RFC][PATCH] Deprecate inb / outb.]
Date: Mon, 16 Jun 2003 15:08:47 +1100
User-agent: KMail/1.5

16 Jun 2003 13:37 Russell Shaw wrote:
> Dmitry K. wrote:
> > 16 Jun 2003 11:45 Russell Shaw wrote:
> >>Dmitry K. wrote:
> >>>16 Jun 2003 06:18 Joerg Wunsch wrote:
> >>>>Basically, it's now no longer (easily) possible to use one
> >>>>of the SFRs as the target of an inline asm statement anyway (see bug
> >>>>ID #2233, we need to update our inline asm docs accordingly).
> >>>
> >>>Examples of SFRs usage:
> >>>
> >>>//#define _SFR_ASM_COMPAT  1       /* needed for second example only       
> >>>*/
> >>>
> >>>#include <avr/io.h>
> >>>
> >>>/* Examples of SFRs as the target of an inline asm statements.
> >>>   For qualitative realization it is necessary to add check:
> >>>   if (__builtin_constant_p((port)))
> >>> */
> >>>#define cbi_atomic(port,bit)    do {                    \
> >>
> >>...
> >>
> >>>} while (0)
> >>
> >>What is the do{...} while(0) for?
> >
> > I shall specify, superfluous here only internal brackets. Removal
> > "do ... while" is undesirable, as, for example, it will be impossible to
> > write:
> >     if (flag)
> >             cbi_atomic(PORTB, 2);   /* excess ';'   */
> >     else
> > ==>  parse error before "else"
>
> Hi,
> The reason i asked is that why couldn't just the curly brackets
> be used like:
>
>    #define cbi_atomic(port,bit)    {                    \
>    ...
>    }

With "do ... while(0)" pair You can treat macro expansion as a function,
making your source code easier to read.  Try example above.
This technique is not AVR specific.





reply via email to

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