En utilisant la bibliothèque P99 (flemme de devoir tout réécrire !) :
#include "p99_if.h"
#define CHECK(condition, label, ...) \
if (!(condition)) { \
fprintf (stderr, "%s, %s, %i\n", __FILE__, __func__, __LINE__); \
P99_IF_EMPTY(__VA_ARGS__) () (fprintf(stderr, __VA_ARGS__);) \
goto label; \
}
CHECK(1, error);
CHECK(1, error, "Data is %d\n", 2);
donne bien:
if (!(1)) { fprintf (stderr, "%s, %s, %i\n", "test.c", __func__, 12); goto error; };
if (!(1)) { fprintf (stderr, "%s, %s, %i\n", "test.c", __func__, 14); fprintf(stderr, "Data is %d\n", 2); goto error; };
Elle est dispo là:
http://p99.gforge.inria.fr/(pour info, c'est 100% standard compliant).