On Tue, Apr 27, 2021 at 05:28:30PM +0100, Julien Grall wrote:
> On 27/04/2021 17:04, Anthony PERARD wrote:
> > On Mon, Apr 05, 2021 at 04:57:06PM +0100, Julien Grall wrote:
> > >   struct cmd_spec {
> > > -    char *cmd_name;
> > > +    const char *cmd_name;
> > >       int (*cmd_impl)(int argc, char **argv);
> > >       int can_dryrun;
> > >       int modifies;
> > > -    char *cmd_desc;
> > > -    char *cmd_usage;
> > > -    char *cmd_option;
> > > +    const char *cmd_desc;
> > > +    const char *cmd_usage;
> > > +    const char *cmd_option;
> > >   };
> > 
> > Those const in cmd_spec feels almost the wrong things to do, but it is
> > also unlikely that we would want to modify the strings in a cmd_spec so
> > I guess that's fine.
> 
> May I ask why you think it feels wrong things to do?
> 
> Using char * to point to literal string [...]

Well, they are no literal string here as we only describe a struct, and
I though that having "const struct cmd_spec" would have been enough. But
I gave a try with only "const struct" and found that the strings could
be modified. So I don't have anything anymore to say about the patch,
and "const char" in the "struct" are necessary.

I just need to fix my intuition about how const works in C, even if I
already know the rule about it.

Cheers,

-- 
Anthony PERARD

Reply via email to