Re: [Gluster-devel] !! operator
Jeff Darcywrote: > Sorry if my comment came off as dismissive. It was not dissmissive. My reply was not ironic, I was gladly surprised to learn something about C syntax. >From an objective code-readability standpoint it's probably a bad > idiom. IMO the root of the problem is the lack of a built-in boolean type in C, but that is not big business. -- Emmanuel Dreyfus http://hcpnet.free.fr/pubz m...@netbsd.org ___ Gluster-devel mailing list Gluster-devel@gluster.org http://www.gluster.org/mailman/listinfo/gluster-devel
Re: [Gluster-devel] !! operator
> Thanks for the explanation. I was able to practice C for 18 years in > numerous projects without having the opportunity to see it. I will got > to bed less ignorant tonight. :-) Sorry if my comment came off as dismissive. I was only trying to explain why I'd assume it's intentional. I'll readily admit that I had the exact same reaction when I first saw this construct. >From an objective code-readability standpoint it's probably a bad idiom. While it is definitely concise, the syntax gives no hint as to its intent, and it's often unnecessary. This and the dozen other instances of !! in our code should probably be eliminated or replaced with a macro. TO_BOOLEAN, perhaps? ___ Gluster-devel mailing list Gluster-devel@gluster.org http://www.gluster.org/mailman/listinfo/gluster-devel
Re: [Gluster-devel] !! operator
Jeff Darcywrote: > It's a common idiom in the Linux kernel/coreutils community. I > thought it was in BSD too. Thanks for the explanation. I was able to practice C for 18 years in numerous projects without having the opportunity to see it. I will got to bed less ignorant tonight. :-) -- Emmanuel Dreyfus http://hcpnet.free.fr/pubz m...@netbsd.org ___ Gluster-devel mailing list Gluster-devel@gluster.org http://www.gluster.org/mailman/listinfo/gluster-devel
Re: [Gluster-devel] !! operator
> I found a !! in glusterfs sources. Is it a C syntax I do not know, a > bug, or just a weird syntax? > > xlators/cluster/afr/src/afr-inode-write.c: > local->stable_write = !!((fd->flags|flags)&(O_SYNC|O_DSYNC)); It's a common idiom in the Linux kernel/coreutils community. I thought it was in BSD too. It's a convenient way to coerce any arbitrary non-zero integer value into a specific value of one, for code that uses integers as booleans. I wouldn't assume it's a bug, since that seems to be precisely what's called for in the snippet you provided, but I guess that means it's weird syntax. ___ Gluster-devel mailing list Gluster-devel@gluster.org http://www.gluster.org/mailman/listinfo/gluster-devel