|
From: | Lorenzo Bettini |
Subject: | Re: the signature of getopt, and getopt_long |
Date: | Wed, 30 Sep 2009 18:40:50 +0200 |
User-agent: | Thunderbird 2.0.0.23 (X11/20090817) |
Hi on a second thought, the cast is useless: if I have a function f(char **argv) that passes argv to a function g(char * const *argv)there's no need to cast, since this does not issue any warning: I can pass something not const to something that expects something cost, can't I? It is the other way round which does not work...
am I right? cheers Lorenzo Sergey Poznyakoff wrote:
Hi Lorenzo,the char * const *argv libc declaration of getopt_long (which looks wrong, since argv might be changed during the parsing, right?)Yes, it is wrong because argv might be permuted by getopt_long. And that's why gnulib's implementation uses __getopt_argv_const in the declaration (see the comment in lib/getopt.in.h:73).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?I believe typecasting to `char *__getopt_argv_const *___argv' would be the best way to handle this. Keep in mind, though, that __getopt_argv_const is a macro, which is defined only if you include gnulib's version of getopt.h. Perhaps some additional #ifdef magic would be required before the cast, e.g.: #ifndef __getopt_argv_const # define __getopt_argv_const const #endif Regards, Sergey
-- 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
[Prev in Thread] | Current Thread | [Next in Thread] |