/* Filename: a.c */
#include <stdlib.h>
#include <getopt.h>
struct argkeys {
const char *name;
int *shortname;
char *helpstr;
char *manstr;
char *description;
};
extern const struct argkeys ArgKeys[];
/* Source: <getopt.h> */
int getopt_long(int argc, char * const argv[], const char *optstring, const struct option *longopts, int *longindex);
extern char *optarg;
extern int optind, opterr, optopt;
const struct argkeys ArgKeys[] = {
{"help", "h", "-h, --help", "-h[--help]", "description"},
{"version", "v", "-v, --version", "-v[--version]", "description"}
};
int main (int argc, char * const argv[], char * const argp[])
{
const struct option long_options[] = {
{ArgKeys[0].name, optional_argument, NULL, ArgKeys[0].shortname},
{ArgKeys[1].name, optional_argument, NULL, ArgKeys[1].shortname},
{NULL, 0, NULL, 0}
};
}
$ cc -Wall -c ./a.c
./a.c:19:5: warning: initialization from incompatible pointer type [enabled by default]
{"help", "h", "-h, --help", "-h[--help]", "description"},
^
./a.c:19:5: warning: (near initialization for ‘ArgKeys[0].shortname’) [enabled by default]
./a.c:20:5: warning: initialization from incompatible pointer type [enabled by default]
{"version", "v", "-v, --version", "-v[--version]", "description"}
^
./a.c:20:5: warning: (near initialization for ‘ArgKeys[1].shortname’) [enabled by default]
./a.c: In function ‘main’:
./a.c:26:9: warning: initialization makes integer from pointer without a cast [enabled by default]
{ArgKeys[0].name, optional_argument, NULL, ArgKeys[0].shortname},
^
./a.c:26:9: warning: (near initialization for ‘long_options[0].val’) [enabled by default]
./a.c:27:9: warning: initialization makes integer from pointer without a cast [enabled by default]
{ArgKeys[1].name, optional_argument, NULL, ArgKeys[1].shortname},
^
./a.c:27:9: warning: (near initialization for ‘long_options[1].val’) [enabled by default]
./a.c:25:25: warning: unused variable ‘long_options’ [-Wunused-variable]
const struct option long_options[] = {
^
./a.c:30:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
Оно то работает, но никак не пойму смысл этих варнингов. Я уже гугл перелопатил... С учу несколько дней всего, так что сильно не пинайте.