I just cry when I see something like this.
I just cry when I see something like this.
Uses C implicit conversions between pointers, integral and boolean operators for something that would be clearly better expressed with an if ().
This type of code wouldn't survive the type of code reviews I used to do.
Clarity trumps clever tricks.
EDIT: To make it clear, if I am reviewing someone's C code, I'll be applying MISRA and Code Complete style rules.
servo = dlsym(NULL, "servo_test") != NULL;
... really too onerous?Also not all uses of ++ are accepted, specially the typical memcpy() interview question, which requires to know operator precedence rules between * and ++.
I assume that's a yes to allowing ++ at all. In my opinion ++ generally does a good job of conveying intent, and !! does a very good job of conveying intent.
- single line statements always in postfix form
- for loops
- exception for the prefix form in for loops with C++ iterators due to performance reasons
Clever C code has its place in hackatons, not in code that needs to survive a few project generations.
That is a reasonable thing to allow, but I personally find that particular use much more confusing and finicky than using !! to coerce to boolean.
It all depends on what people read stuff like `!!` as. In a project where that's used often (I assume in CEF there are a whole lot more lines like that one near it), the intention is clear, because people will be reading `!!` as "Coerce to bool". Some won't, agreed. But in the context of a project where it's used often, this isn't as much of a problem.
For example, `fork()` when used is not clear at all about what's going on to someone not familiar with it, but people still use it for stuff, and people reading it know what the intention was if they've had some experience with the language/library.
After lots of use things like `!!` get a concrete intention ascribed to them.
But yes, it can be more explicit so it perhaps should have been.
I mean, if it's forbidden by your particular coding style then fair enough but it's a bit harsh to cry at this bit of code because it makes use of it.
For what it's worth I made a quick grep for ' !!' in the linux kernel and found 2439 matches. I think it's more a matter of subjective taste than a sign of poor coding.
And I maintain that any C compiler worth its salt will handle '!!' just fine, it's a really simple optimization (and even if you consider double-negations poor style in your code it'll crop up quite often while inlining functions or expanding macros for instance).