Re: [PATCH 06/10] misc: clarify ternary operators with parentheses

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

 



On Sun, Apr 23, 2017 at 09:58:17PM +0100, Sami Kerola wrote:
> Compilers probably got these evaluations right, but it is best not to leave
> any room of interpretation what is the human intention.

 Not sure if I like the patch.... the operators precedence is
 important to understand C code, not sure if we want to use '(' ')'
 everywhere to keep readers uneducated. 
 
 Yes, in some complex conditions it makes sense (multi-line if()), but
 this is not the case.

> -	return lb->flags & FDISK_LABEL_FL_REQUIRE_GEOMETRY ? 1 : 0;
> +	return (lb->flags & FDISK_LABEL_FL_REQUIRE_GEOMETRY) ? 1 : 0;

 All the "<someting> ? 1 : 0" is non-elegant, what about:

     return !!(lb->flags & FDISK_LABEL_FL_REQUIRE_GEOMETRY);

 to keep code simple, fast and humans happy :)

    Karel

-- 
 Karel Zak  <kzak@xxxxxxxxxx>
 http://karelzak.blogspot.com
--
To unsubscribe from this list: send the line "unsubscribe util-linux" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux