54Fermer56
deleted2Le 11/11/2014 à 10:44
RHJPP -> il marche comment le ##__VA_ARGS__ ?
Si j'en crois mes essais :
#include <stdio.h>
#include <stdbool.h>

#define CHECK(condition, label, ...)                                  \
  if (!(condition)) {                                                 \
    fprintf(stderr, "%s, %s, %i\n", __FILE__, __func__, __LINE__);    \
    fprintf(stderr, ##__VA_ARGS__, "");                               \
    goto label;                                                       \
  }

int main (int argc, char** argv)
{
  CHECK (false, pouet, "pwic\n")

    pouet:
  return 1;
}

Ca marche quand je compile : folco@Foch:~$ gcc -std=c11 test.c -o test
Mais je comprends pas, pourquoi ## et non # ? Je voulais juste stringifier, pourtant je vois bien ce qui se passe :
gcc -E test.c
avec # : if (!(0)) { fprintf(stderr, "%s, %s, %i\n", "test.c", __func__, 13); fprintf(stderr, "\"pwic\n\"", ""); goto pouet;
avec ## : if (!(0)) { fprintf(stderr, "%s, %s, %i\n", "test.c", __func__, 13); fprintf(stderr, "pwic\n", ""); goto pouet;

Donc j'ai bien le résultat que je veux, et je t'en remercie, mais je comprends pas la coup du ## triso Pour moi, ça "stringifiais" des symboles, ça les concaténait, puis ça les déstringifiait pour en refaire un symbole, comme ici : https://gcc.gnu.org/onlinedocs/cpp/Concatenation.html#Concatenation
Je croyais comprendre que ## prend un symbole de chaque coté en argument, ce qui n'est pas le cas ici.
=> En fait, je ne vois pas du tout l'intérêt du ## ici, j'ai l'impression que j'ai la meme sortie en passant directement __VA_ARGS__

En tout cas, merci encore, parce que "ça marche" ! grin