74Fermer76
deleted2Le 12/11/2014 à 15:02
, label, ##__VA_ARGS__)Bon, vala maintenant : #define IF_TRUE(condition, label, ...) \ if (condition) { \ if (*#__VA_ARGS__) { \ fprintf (stderr, "ERROR: "); \ fprintf (stderr, ##__VA_ARGS__, ""); \ fprintf (stderr, "\n"); \ } \ fprintf (stderr, "TRACE: %s:%i, in %s()\n", __FILE__, __LINE__, __func__); \ goto label; \ } #define IF_FALSE(condition, label, ...) IF_TRUE (!(condition)
Ca donne des trucs comme ça :
folco@Foch:~/fpgc/Debug$ ./fpgc
ERROR: Couldn't open ../spr/ButtonExit_out.png
TRACE: /home/folco/fpgc/src/Ressources.c:18, in LoadSpriteFile()
TRACE: /home/folco/fpgc/src/Ressources.c:32, in InitRessources()
TRACE: /home/folco/fpgc/src/main.c:15, in main()
folco@Foch:~/fpgc/Debug$ 

Par contre, je dois passer -Wno-format-extra-args pour éviter un warning, dans le cas où je fournis une chaine avec des donénes à formatter, genre IF_TRUE (m_count == GS_COUNT_MAX, Exit, "ERROR: max game state reached, %i", GS_COUNT_MAX), parce qu'il n'y a que %i à formater, et gcc voit GS_COUNT_MAX et le "" de la macro. J'ai pas trouvé comment éviter ça (sans utiliser une lib telle celle proposée par PpHd).