Re: 'do {} while (0)' replacement

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

 



On Friday 10 October 2008, Ian Lance Taylor wrote:
> Frank Mehnert <fm3@xxxxxxxxxxxxxxxxxxxx> writes:
> > My problem is the following:
> >
> >   #define BREAK_ON_ERROR(i)   \
> >     if (1)                    \
> >     {                         \
> >       if (i < 0)              \
> >         break;                \
> >     }                         \
> >     else do                   \
> >     {                         \
> >     } while (0)               \
> >
> >   int foo(void)
> >   {
> >     for (;;)
> >     {
> >       int bar = 1, buzz = 2;
> >       if (bar)
> >         BREAK_ON_ERROR(buzz);
> >     }
> >   }
> >
> > gcc-4.3 will warn with
> >
> >   'warning: suggest explicit braces to avoid ambiguous `else'
>
> Use a gcc extension.
>
> #define BREAK_ON_ERROR(i) ({ if (i < 0) break; })

That was it, thank you _very_ much!

Kind regards,

Frank
-- 
## Dept. of Computer Science, Dresden University of Technology, Germany ##
## http://os.inf.tu-dresden.de/~fm3                                     ##

Attachment: signature.asc
Description: This is a digitally signed message part.


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux