[Top][All Lists]

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

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

From: Boris Dušek
Subject: [PATCH 2/3] Cleanup execution of commands in dummy
Date: Wed, 25 Jul 2012 11:03:15 +0200

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 ... :-)

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.

Let me know what you think, it's no problem for me to correct it to the
style you propose.

reply via email to

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