'do {} while (0)' replacement
Frank Mehnert
fm3@os.inf.tu-dresden.de
Thu Oct 9 08:01:00 GMT 2008
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 ##
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part.
URL: <https://gcc.gnu.org/pipermail/gcc-help/attachments/20081009/c6d158d3/attachment.sig>
More information about the Gcc-help
mailing list