L
LibraryUser
The said:.... snip ...You could try something like the following instead. (There are
probably more efficient ways to do this.)
int parse_args(char cmd_arg[])
{
if (strcmp(cmd_arg, "test1") == 0)
{
printf("%s\n", cmd_arg);
return 0;
}
else if (strcmp(cmd_arg, "test2") == 0)
The else is superflous here as when the if is true the codeflow
ends with the return statement. So only the case that if fails
is over to handle.
{
printf("%s\n", cmd_arg);
return 0;
}
else
Another superflous else
return 1;
}
On the contrary, the "superfluous" elses are extremely useful for
emphasizing the one-of-many conditions met. There is no
intrinsic reason for the individual cases to exit with a 'return'
statement, and the code would be clearer without such (single
exit point).
This is the type of structure used to implement a switch on
conditions that are not usable as switch cases.
In general, don't obfuscate code for evanescent possible
optimizations.