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

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

 



Hi Richard,

On Wednesday 08 October 2008, Richard Harvey Chapman wrote:
> 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.

thank you, but ...

> #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)                 \

This changes the semantics: The BREAK_ON_ERROR() macro should be
handled as one compound statement. The following statement should
work as well:

  if (bar)
    BREAK_ON_ERROR(buzz);
  else
    BREAK_ON_ERROR(buzz1);

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