Liste des Groupes | Revenir à cl c |
I have this macro:The whole idea of `do { ... } while(false)` idiom for writing complex macros is based on _not_ including that `;` after `while(false)` into the macro. Meanwhile, you botched the whole thing by adding that `;` there.
#define WARN(...) \
do { \
fprintf(stderr, "%s#%d: ", __FILE__, __LINE__); \
fprintf(stderr, __VA_ARGS__); \
} while (0);
which I use like this:
total++;
if (failed) {
WARN("failed because...");
} else
ok++;
I would prefer to be able to write this instead:
total++;
if (failed)
WARN("failed because...");
else
ok++;
but doing so results in a compiler error:
error: 'else' without a previous 'if'
Les messages affichés proviennent d'usenet.