From: Paul M. <le...@li...> - 2007-08-15 05:01:38
|
On Wed, Aug 15, 2007 at 12:03:54PM +0900, Magnus Damm wrote: > > I've never seen things like > > data[!primary] > > before and was really surprised it works. What about > > data[1 - primary] > > or > > data[1 ^ primary] > > If you ask me this is easier to understand and more important this > > complies with any C implementation. > > The C standard defines false as 0 and any other value is defined as > > true. So !0 could be anything. > > Does this mean that you dislike the idea of "!!" as well? =) > Grep the kernel sources and you'll find that here and there... > You can find a lot of stupid things in the kernel, most of drivers/ for example. Just because it's in the kernel doesn't mean you should blindly follow all of its silly conventions. !! does end up being pretty expensive on platforms that have trivial test-and-branch opcodes, even if it's more obvious when used in the code. The main area where it ends up being useful is for places where you need to test a value but do not want to have to emit the shift and other things for it (especially for platforms that can't do large immediates relative to the bit position), but it is not a blanket win. ;-) > I think it's important that people easily can read and understand the > code, but I'm not sure if your proposal makes it any more readable. > Feel free to cook up a patch and if other people prefer that as well > then I'm all for it. =) > More comments or additional variables with some more descriptive names might deal with whatever confusion arises from it. Patches to rework the ambiguity are always a good thing. |