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

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

 



I was able to get rid of the warning by simply removing the "else". I had to modify your program slightly to run it to completion.

gcc (GCC) 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)


#include <stdio.h>

#define BREAK_ON_ERROR(i)     \
 if (1)                      \
 {                           \
   if (i < 0)                \
     break;                  \
 }                           \
 else do                     \
      {                      \
      } while (0)            \


#define BREAK_ON_ERROR2(i)     \
 if (1)                      \
 {                           \
   if (i < 0)                \
     break;                  \
 }                           \
 do                          \
 {                           \
 } while (0)                 \


int foo(void)
{
 int bar = 1, buzz = 2;
 for (;;)
 {
   if (bar)
     BREAK_ON_ERROR2(buzz);
   buzz--;
 }

 printf("Done. buzz = %d\n", buzz);

 return(0);
} // foo()

int main()
{
 return(foo());
} // main()



[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