replacing if-then-else strcmp ladders with switch cases
Valdis Kl=?utf-8?Q?=c4=93?=tnieks
valdis.kletnieks at vt.edu
Sat Jun 13 01:02:16 EDT 2020
On Fri, 12 Jun 2020 12:05:55 -0600, jim.cromie at gmail.com said:
> considering lib/dynamic_debug.c
> we have
>
> ...
> } else if (!strcmp(words[i], "module")) {
> rc = check_set(&query->module, words[i+1], "module");
> } else if (!strcmp(words[i], "format")) {
> ...
>
> are there any built-in hash functions which would allow this ?
>
> switch (keyword) {
> case Hash("module"):
> ..... break;
> case Hash("format"):
> .... break;
> default: return -EINVAL
> }
There's hash functions. But they're all cryptographic hashes that return
things that are far too many bits to use as the index of a switch.
Also, you have the problem that the cases of a switch have to be something
that can be evaluated at compile time....
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 832 bytes
Desc: not available
URL: <http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20200613/28e4a2c1/attachment.sig>
More information about the Kernelnewbies
mailing list