Re: GNU Gengetopt 2.22

Lorenzo Bettini <[email protected]> Tue, 15 Jan 2008 22:52:57 +0100
Newsgroups gmane.comp.gnu.gengetopt.general
Message-ID <[email protected]>
Andre Noll wrote:
>>> Similarly, if gengetopt is compiled on Mac, and then configured and
>>> built on Linux, it results in
>>>
>>> 	argsdef.o: file not recognized: File format not recognized
>>> 	
>>> However, this is not a serious issue because "make clean" solves the
>>> problem.
>>>
>> mh... I don't think this is the expected behavior: issueing another 
>> configure might change the config.h and the files that include it will 
>> be recompiled, but not all files are expected to include it; actually if 
>> you build a package for different platforms you should run each 
>> configure in a separate directory (one for each different configure).
> 
> OK. Another solution would be to let all object files depend on Makefile
> which is also generated by configure.
> 

mhh... but I don't know whether this can be made in a clean way with 
autotools...  I'm pretty sure that configure for different architectures 
should be run in different directories...

>>> Finally, when compiling audiod.cmdline.c, a file generated by
>>> gengetopt-2.22, I see the following warning, which didn't show up
>>> when using earlier versions of gengetopt:
>>>
>>> audiod.cmdline.c: In function 'audiod_cmdline_parser_release':
>>> audiod.cmdline.c:337: warning: dereferencing type-punned pointer will 
>>> break strict-aliasing rules
>>>
>>> The offending line 337 in audiod.cmdline.c is
>>>
>>> 	  free_multiple_field (args_info->user_allow_given, (void 
>>> 	  **)&(args_info->user_allow_arg), &(args_info->user_allow_orig));
>>>
>>> And free_multiple_field() looks like this:
>>>
>>> static void
>>> free_multiple_field(unsigned int len, void **arg, char ***orig)
>>> {
>>>  unsigned int i;
>>>  if (*arg) {
>>>    for (i = 0; i < len; ++i)
>>>      {
>>>        free_string_field(&((*orig)[i]));
>>>      }
>>>
>>>    free (*arg);
>>>    *arg = 0;
>>>    free (*orig);
>>>    *orig = 0;
>>>  }
>>> }
>>>
>>> Why you are using void ** as the second parameter "arg" when the function
>>> is only using *arg? Wouldn't it be better to generate
>>>
>>> static void
>>> free_multiple_field(unsigned int len, void *arg, char ***orig)
>>> {
>>>  unsigned int i;
>>>  if (arg) {
>>>    for (i = 0; i < len; ++i)
>>>      {
>>>        free_string_field(&((*orig)[i]));
>>>      }
>>>
>>>    free (arg);
>>>    free (*orig);
>>>    *orig = 0;
>>>  }
>>> }
>>>
>>> instead? This would allow to get rid of the cast in the offending line.
>>> The only drawback I can see is that args_info->user_allow_arg is not
>>> set to NULL by free_multiple_field() when using this approach.
>> mh... setting that arg to null is crucial (since what is freed could be 
>> re-used internally), but probably I could set it to NULL after that 
>> function call, I'll take a look at this.
> 
> I see. An alternative for getting rid of this warning is to introduce an
> intermediate (void *) cast:
> 
> 	free_multiple_field (args_info->user_allow_given, (void **)(void *)&(args_info->user_allow_arg), &(args_info->user_allow_orig));
>                                                                    ^^^^^^^^

well if this does not generate the warning I think that'd be a better 
solution :-)

>> Actually, I don't get this warning, so thanks for reporting it.
> 
> You need to compile with -Wstrict-aliasing (included in -Wall) and
> with -fstrict-aliasing (enabled at levels -O2, -O3, -Os).

actually I always test compilations with -Wall but I don't get this 
warning... probably because you're using a different architecture?  Is 
this warning something to worry about?  I mean: I want to remove it, but 
does the warning means that the above code can do something wrong?

thanks
	Lorenzo

P.S. there are also other warnings that I still need to remove; Gyozo, I 
didn't remember to remove all the warnings you told me about; I'll do 
that in the very near future :-)

-- 
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