help-gengetopt
[Top][All Lists]
Advanced

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

Re: [help-gengetopt] a bug, when defining a multiple option with default


From: Yegor Yefremov
Subject: Re: [help-gengetopt] a bug, when defining a multiple option with default value
Date: Wed, 13 Jun 2007 09:24:19 +0200
User-agent: Thunderbird 2.0.0.0 (Windows/20070326)

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




reply via email to

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