Optional braces
Marco Leise
Marco.Leise at gmx.de
Fri Aug 26 05:20:29 PDT 2011
Am 26.08.2011, 13:10 Uhr, schrieb bearophile <bearophileHUGS at lycos.com>:
> Marco Leise:
>
>> Is (!x & y) an issue or is it rather people omitting spaces in their
>> code
>> !x&y ?
>
> This topic was already discussed in past, in two threads, this one of
> them:
> http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=135741
>
> The Coccinelle tool has found a large number of !x & y bug patterns in
> already debugged high-quality C/C++ code. Search for "Correct
> occurrences of !x&y" in this page:
> http://coccinelle.lip6.fr/impact_linux.php
>
> See also, a good lint catches this bug:
> http://d.puremagic.com/issues/show_bug.cgi?id=5814
And once these lints complain about 1 + 2 * 3 being ambiguous I lose all
hope in mankind. But point taken, there is a provably large number of such
bugs. In fact they can be narrowed down to 'check if a flag is disabled'
as in this example: "if (!(flags & SOME_FLAG))".
> It's a common mistake, it causes significant troubles, it's easy to
> catch, avoiding it is cheap syntax-wise, and there is a precedent
> similar case already implemented in D.
Ok, I get it.
>> If in the above case we are forced to write ((!x) & y) that's ... LISP.
>
> Nope, it asks for just one pair of parentheses, like:
> !(x & y)
> Or:
> (!x) & y
I guess "(!x) & y" is a rare case anyway. I though of "if ((!x) && y)".
Does your enhancement include other operators like '&&' or is it
practically just for the 'check if flag is disabled' case?
>> At least I'm not convinced by what is in the bug report.
>
> You will have to bring on the table stronger evidence that this an
> useless change, if you want to refuse the enhancement request 5409.
> Walter and Don have accepted it, I think. I don't know what Andrei
> thinks of it.
>
> Bye,
> bearophile
More information about the Digitalmars-d
mailing list