I actually did this intentionally. x = y == z; pattern looked too
obscure to my taste, tbh.
It's certainly a question of taste and obviously there is nothing
wrong with yours.
Maybe adding parentheses makes the below look less obscure to you?
x = (y == z);
My taste would run to something like:
---
tools/lib/bpf/libbpf.c | 25 +++++++++++++++++--------
1 file changed, 17 insertions(+), 8 deletions(-)
@@ -1469,25 +1469,34 @@ static int set_kcfg_value_tri(struct extern_desc *ext, void *ext_val,charvalue){switch(ext->kcfg.type){-caseKCFG_BOOL:+caseKCFG_BOOL:{+bool*p=ext_val;+if(value=='m'){pr_warn("extern (kcfg) %s=%c should be tristate or char\n",ext->name,value);return-EINVAL;}-*(bool*)ext_val=value=='y'?true:false;+*p=(value=='y');break;-caseKCFG_TRISTATE:+}+caseKCFG_TRISTATE:{+enumlibbpf_tristate*p=ext_val;+if(value=='y')-*(enumlibbpf_tristate*)ext_val=TRI_YES;+*p=TRI_YES;elseif(value=='m')-*(enumlibbpf_tristate*)ext_val=TRI_MODULE;+*p=TRI_MODULE;else/* value == 'n' */-*(enumlibbpf_tristate*)ext_val=TRI_NO;+*p=TRI_NO;break;-caseKCFG_CHAR:-*(char*)ext_val=value;+}+caseKCFG_CHAR:{+char*p=ext_val;++*p=value;break;+}caseKCFG_UNKNOWN:caseKCFG_INT:caseKCFG_CHAR_ARR:
I actually did this intentionally. x = y == z; pattern looked too
obscure to my taste, tbh.
It's certainly a question of taste and obviously there is nothing
wrong with yours.
Maybe adding parentheses makes the below look less obscure to you?
x = (y == z);
Yeah, I think this would be explicit enough. But let's keep the *(bool
*) cast and keep switch code shorter and without extra {} block.
My taste would run to something like:
---
tools/lib/bpf/libbpf.c | 25 +++++++++++++++++--------
1 file changed, 17 insertions(+), 8 deletions(-)
I actually did this intentionally. x = y == z; pattern looked too
obscure to my taste, tbh.
It's certainly a question of taste and obviously there is nothing
wrong with yours.
Maybe adding parentheses makes the below look less obscure to you?
x = (y == z);
That just leads to people thinking conditionals need to be in parentheses
and then getting the priorities for ?: all wrong as in:
x = a + (b == c) ? d : e;
It would (probably) be better to make 'ext_val' be a union type
(probably a 'pointer to a union' rather than a union of pointers)
so that all the casts go away.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)