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
Il n'y a pas un moyen d'avoir un truc qui marche vraiment ? (j'ai essayé un certain nombre de trucs, mais rien ne passait... et je ne suis pas un dieu des structures en C
)
(D'ailleurs, j'ai converti certains de getopt à ça parce que c'est plus portable, sans devoir copier-coller le code de getopt partout où ce n'est pas dans la libc système.)
kevin, utiliser getopt est une horreur et vive faire un parseur a la main (surtout que c'est plutot simple.)
et ce sont tous les warnings postés dans le