On Fri, May 8, 2015 at 2:08 PM, Sébastien Guimmara <sebastien.guimmara@xxxxxxxxx> wrote: > On 05/06/2015 05:16 AM, Eric Sunshine wrote: >> >> On Mon, May 4, 2015 at 4:28 PM, Sébastien Guimmara >>> >>> + >>> + if (group1 == group2) >>> + return 0; >>> + if (group1 > group2) >>> + return 1; >>> + else >>> + return -1; >> >> >> Do you also want to sort the commands alphabetically within group? >> That is, something like this? >> >> struct cmdname_help *e1 = elem1; >> struct cmdname_help *e2 = elem2; >> >> if (e1->group < e2->group) >> return -1; >> if (e1->group > e2->group) >> return 1; >> return strcmp(e1->name, e2->name); >> >>> +} > > > Your version raises: > > help.c: In function ‘cmd_group_cmp’: > help.c:223:28: warning: initialization discards ‘const’ qualifier from > pointer target type [enabled by default] > struct cmdname_help *e1 = elem1; > ^ > help.c:224:28: warning: initialization discards ‘const’ qualifier from > pointer target type [enabled by default] > struct cmdname_help *e2 = elem2; > ^ > > With the cast: > > struct cmdname_help *e1 = (struct cmdname_help*)elem1; > > It compiles without a warning (gcc (Ubuntu 4.8.2-19ubuntu1) 4.8.2) > > I'd rather change the type of struct cmdname_help to be const, such that it reads: const struct cmdname_help *e1 = elem1; const struct cmdname_help *e2 = elem2; if (e1->group < e2->group) return -1; if (e1->group > e2->group) return 1; return strcmp(e1->name, e2->name); instead of casting if possible. -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html