bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

the signature of getopt, and getopt_long


From: Lorenzo Bettini
Subject: the signature of getopt, and getopt_long
Date: Sun, 27 Sep 2009 19:50:19 +0200
User-agent: Thunderbird 2.0.0.23 (X11/20090817)

Hi

I'm the author and maintainer of GNU gengetopt, http://www.gnu.org/software/gengetopt/, which generates a C function that uses getopt_long function to parse the command line options, to validate them and fills a struct.

I'm using gnulib's getopt module to make gengetopt compilable also on systems without a (possibly correct implementation of) getopt functions.

gengetopt generates a function with the signature

int cmdline_parser (int argc, char * const *argv,
  struct gengetopt_args_info *args_info);

because it mimic the

char * const *argv

libc declaration of getopt_long (which looks wrong, since argv might be changed during the parsing, right?)

when compiling the generated parser using the gnulib version I get the warnings

warning: passing argument 2 of 'rpl_getopt_long' discards qualifiers from pointer target type

since the gnulib version declares it like this

getopt_long (int ___argc, char *__getopt_argv_const *___argv,
                        const char *__shortopts,
                        const struct option *__longopts, int *__longind)

now, I'd like to avoid the warning in the generated parser when using gnulib, but I'd like to avoid it also when using libc getopt_long version...

what would you suggest?

change my generated function signature to

int cmdline_parser (int argc, char **argv,
  struct gengetopt_args_info *args_info);

and then, internally perform a cast to

char *__getopt_argv_const *___argv

before invoking getopt_long?

many thanks in advance
        Lorenzo

--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
ICQ# lbetto, 16080134     (GNU/Linux User # 158233)
HOME: http://www.lorenzobettini.it MUSIC: http://www.purplesucker.com
http://www.myspace.com/supertrouperabba
BLOGS: http://tronprog.blogspot.com  http://longlivemusic.blogspot.com
http://www.gnu.org/software/src-highlite
http://www.gnu.org/software/gengetopt
http://www.gnu.org/software/gengen http://doublecpp.sourceforge.net





reply via email to

[Prev in Thread] Current Thread [Next in Thread]