Re: a bug, when defining a multiple option with default value

Yegor Yefremov <[email protected]>
Newsgroups gmane.comp.gnu.gengetopt.general
Message-ID <[email protected]>
Lorenzo Bettini wrote:
> Yegor Yefremov wrote:
>   
>> Dear list,
>>
>> I found a bug, when defining a multiple option with default value. The
>> value is assigned but the given variable is not increased:
>>
>> else /* set the default value */
>>    {
>>      if (! args_info->seri_arg && ! args_info->seri_given)
>>        {
>>          args_info->seri_arg = (char * *) malloc (sizeof (char *));
>>          args_info->seri_arg [0] = gengetopt_strdup("/dev/ttyS1");
>>          args_info->seri_orig = (char **) malloc (sizeof (char *));
>>          args_info->seri_orig [0] = NULL;
>>          // here should the variable be increased
>>        }
>>    }
>>
>> // here args_info->seri_given takes 0 value, so I can't access
>> args_info->seri_arg
>> args_info->seri_given += local_args_info.seri_given;
>> local_args_info.seri_given = 0;
>>
>>     
>
> this is not actually a bug: the given field says how many times that
> option is specified on the command line (or in a configuration file), so
> if an option has a default value, then given can be 0 and this tells you
> that the user specified no option (if given was incremented even when
> the default value is set, then you would have no way to tell whether the
> user specified).
>
> You can still access the default value since you know that it's the
> first element of the array
>
> NOTICE: you must be aware of default values in a program, so that, in
> case of a multiple option, you can safely assume that the first element
> of the array argument is always set.
>
> Is this issue clearer?
>
> hope to hear from you soon
> cheers
> 	Lorenzo
>
>   
Thanks. The issue is clearer now ;-) It was not a bug it was a feature.

Cheers
    Yegor
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.