speechd-discuss
[Top][All Lists]
Advanced

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

[PATCH 2/3] Cleanup execution of commands in dummy


From: Trevor Saunders
Subject: [PATCH 2/3] Cleanup execution of commands in dummy
Date: Wed, 25 Jul 2012 08:15:27 -0400

On Wed, Jul 25, 2012 at 11:03:15AM +0200, Boris Du?ek wrote:
> 24. 7. 2012 v 22:35, Trevor Saunders:
> 
> >> +#define PLAY_CMD(cmd) #cmd " " DATADIR "/dummy-message.wav > /dev/null 2> 
> >> /dev/null"
> >> +  static const char *const play_cmds[] = {
> >> +          PLAY_CMD(play),
> >> +          PLAY_CMD(aplay),
> >> +          PLAY_CMD(paplay),
> >> +          NULL
> >> +  };
> > 
> >> +  for (play_cmd = play_cmds; *play_cmd != NULL; ++play_cmd) {
> > 
> > the NULL termination seems a little strange, instead you could do
> > for (i = 0; i < sizeof(cmds)/sizeof(cmds[0]); i++)
> > though it would be nice if sizeof(array)/sizeof(array[0]) was a macro.
> 
> I saw such pattern a lot, e.g. getopt etc. I like it because it seems
> consistent with how you work with linked lists - get a pointer to the
> first item and then process it and get next item until it is null,
> which signals the end of list. The real solution would be if C had
> real arrays ... :-)

true, but this is an array not a linked list.

> One way where it is actually better is that there is always a comma
> after any PLAY_CMD macro. If the array was not NULL-terminated, then
> the last PLAY_CMD would not have comma in the end. If adjustments would
> then be made where the last element would become non-last and/or vice
> versa, the diff would get confused. In NULL-terminated style, there is
> always a comma after PLAY_CMD, so any adjustments are from diff
> perspective just reordering and adding/deleting PLAY_CMD rows, but
> not modifying them.

well, C should just allow a , after the last element, but personally
I've read diffs to plenty of structs / enums that don't have a dummy
element and it doesn't really bother me much.

anyway I think it looks kind of weird, but no big deal.

Trev


> 
> Let me know what you think, it's no problem for me to correct it to the
> style you propose.
> _______________________________________________
> Speechd mailing list
> Speechd at lists.freebsoft.org
> http://lists.freebsoft.org/mailman/listinfo/speechd



reply via email to

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