
Pour commencer, j'ai naturellement pris l'exemple fourni
while (1) { static struct option long_options[] = { /* These options set a flag. */ {"verbose", no_argument, &verbose_flag, 1}, {"brief", no_argument, &verbose_flag, 0}, /* These options don't set a flag. We distinguish them by their indices. */ {"add", no_argument, 0, 'a'}, {"append", no_argument, 0, 'b'}, {"delete", required_argument, 0, 'd'}, {"create", required_argument, 0, 'c'}, {"file", required_argument, 0, 'f'}, {0, 0, 0, 0} }; /* getopt_long stores the option index here. */ int option_index = 0; c = getopt_long (argc, argv, "abc:d:f:", long_options, &option_index); /* Detect the end of the options. */ if (c == -1) break; }
Manque de pot, ça ne compile pas...
J'ai vite trouvé qu'en changeant long_options[] par *long_options, ça compilait mieux, mais ce n'est pas encore ça :
statistic.c:849: warning: braces around scalar initializer statistic.c:849: warning: (near initialization for ‘long_options’) statistic.c:849: warning: initialization from incompatible pointer type statistic.c:849: warning: excess elements in scalar initializer statistic.c:849: warning: (near initialization for ‘long_options’) statistic.c:849: warning: excess elements in scalar initializer statistic.c:849: warning: (near initialization for ‘long_options’) statistic.c:849: warning: excess elements in scalar initializer statistic.c:849: warning: (near initialization for ‘long_options’)
Et ça, pour chaque ligne du tableau long_opts

