argtable / argtable3

A single-file, ANSI C, command-line parsing library that parses GNU-style command-line options.
http://www.argtable.org
Other
377 stars 65 forks source link

Multi-command example has compiler warnings caused by missing the "const" qualifier #95

Closed tomghuang closed 6 months ago

tomghuang commented 6 months ago

The new multi-command API arg_make_help_msg and arg_make_syntax_err_help_msg miss the const qualifier for the command name parameter, which may cause the following compiler warnings:

/mnt/d/Projects/teopa-book/ex-int-cli-multi/src/cmdhelp.c: In function ‘cmdhelp_proc’:
/mnt/d/Projects/teopa-book/ex-int-cli-multi/src/cmdhelp.c:55:43: warning: passing argument 2 of ‘arg_make_syntax_err_help_msg’ discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
   55 |     if (arg_make_syntax_err_help_msg(res, cmdhelp_name(), help->count, nerrors, argtable, end,
      |                                           ^~~~~~~~~~~~~~
In file included from /mnt/d/Projects/teopa-book/ex-int-cli-multi/src/cmdhelp.h:17,
                 from /mnt/d/Projects/teopa-book/ex-int-cli-multi/src/cmdhelp.c:14:
/mnt/d/Projects/teopa-book/ex-int-cli-multi/src/argtable3.h:263:66: note: expected ‘char *’ but argument is of type ‘const char *’
  263 | ARG_EXTERN int arg_make_syntax_err_help_msg(arg_dstr_t ds, char* name, int help, int nerrors, void** argtable, struct arg_end* end, int* exitcode);
      |                                                            ~~~~~~^~~~
[ 80%] Building C object CMakeFiles/climulti.dir/src/cmdversion.c.o
/mnt/d/Projects/teopa-book/ex-int-cli-multi/src/cmdversion.c: In function ‘cmdversion_proc’:
/mnt/d/Projects/teopa-book/ex-int-cli-multi/src/cmdversion.c:46:43: warning: passing argument 2 of ‘arg_make_syntax_err_help_msg’ discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
   46 |     if (arg_make_syntax_err_help_msg(res, cmdversion_name(), help->count, nerrors,
      |                                           ^~~~~~~~~~~~~~~~~
In file included from /mnt/d/Projects/teopa-book/ex-int-cli-multi/src/cmdversion.h:17,
                 from /mnt/d/Projects/teopa-book/ex-int-cli-multi/src/cmdversion.c:14:
/mnt/d/Projects/teopa-book/ex-int-cli-multi/src/argtable3.h:263:66: note: expected ‘char *’ but argument is of type ‘const char *’
  263 | ARG_EXTERN int arg_make_syntax_err_help_msg(arg_dstr_t ds, char* name, int help, int nerrors, void** argtable, struct arg_end* end, int* exitcode);
      |

We should add the const qualifier to the API.