[prev in list] [next in list] [prev in thread] [next in thread] 

List:       ros-dev
Subject:    Re: [ros-dev] [ros-diffs] [dgorbachev] 39422: Fix bug
From:       Timo Kreuzer <timo.kreuzer () web ! de>
Date:       2009-02-17 17:03:12
Message-ID: 499AEDD0.9070907 () web ! de
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


Ged schrieb:
> James Hawkins wrote: 
>
>   
>> The parentheses are not needed?  You better check your C book for
>> operator precedence.  && has higher precedence than ||, so in this
>> case the parentheses are needed.  This is also why using parentheses
>> is a good idea, because you never know if the original author has any
>> idea about operator precedence.  The use of parentheses makes the
>> original intention clear to other authors.
>>     
>
> An absolutely perfect example which nicely backs up my original argument.
> I feel I now have nothing more to add.  :)
>   
Ok, but I have.
The example that I fucked up, was an example where I wanted to say that
parantheses are useful.
Whereas I think in the case of || and && they should not be added as you
can break a warning.

The arguments that have been brought up pro parenthesing are perfectly
valid (except Alex' one maybe :)) when it comes to generic use of
parentheses. But none of them is valid is this special case.
If you want to generalize this ad infinitum, let's start adding
parentheses around other things, too.

What about
    printf(Format, String + strlen(Prefix), i + 1);
You better add some parentheses around (i + 3) so it won't be mistaken for
    printf(Format, String + (strlen(Prefix), i) + 1);

What about this:

    (Callback->RoutineBlock).Object = NULL;
   
ExfReleaseRundownProtectionEx((&(CallbackRoutineBlock->RundownProtect)),
((Value.RefCnt) + 1));
    NewValue.Object =
(InterlockedCompareExchangePointer((&(FastRef->Object)),
                                                           
(NewValue.Object),
                                                           
(Value.Object)));
    for (((Entry = (Head->Flink)), (i = 0)); ((i < (Info->Depth)) &&
((Entry->Flink) != NULL)); ((i++), (Entry = (Entry->Flink))))

Looks like crap, doesn't it?

You need to draw the line somewhere.
IMO there's no use in adding parentheses around something when any
different parenthesing wouldn't make sense.
You cannot mistake if (a < 1 && b < 2) for if (a < (1 && b) < 2) as the
second doesn't make sense.

Now I'd just like to see only one concrete example of when adding
parentheses around comparisons seperated by || / && has an advantage
over not adding them.





[Attachment #5 (text/html)]

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-2" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Ged schrieb:
<blockquote cite="mid:001201c990d5$e26f7980$a74e6c80$@com" type="cite">
  <pre wrap="">James Hawkins wrote: 

  </pre>
  <blockquote type="cite">
    <pre wrap="">The parentheses are not needed?  You better check your C book for
operator precedence.  &amp;&amp; has higher precedence than ||, so in this
case the parentheses are needed.  This is also why using parentheses
is a good idea, because you never know if the original author has any
idea about operator precedence.  The use of parentheses makes the
original intention clear to other authors.
    </pre>
  </blockquote>
  <pre wrap=""><!---->
An absolutely perfect example which nicely backs up my original argument.
I feel I now have nothing more to add.  :)
  </pre>
</blockquote>
Ok, but I have.<br>
The example that I fucked up, was an example where I wanted to say that
parantheses are useful.<br>
Whereas I think in the case of || and &amp;&amp; they should not be
added as you can break a warning.<br>
<br>
The arguments that have been brought up pro parenthesing are perfectly
valid (except Alex' one maybe :)) when it comes to generic use of
parentheses. But none of them is valid is this special case.<br>
If you want to generalize this ad infinitum, let's start adding
parentheses around other things, too. <br>
<br>
What about<br>
    printf(Format, String + strlen(Prefix), i + 1);<br>
You better add some parentheses around (i + 3) so it won't be mistaken
for<br>
    printf(Format, String + (strlen(Prefix), i) + 1);<br>
<br>
What about this:<br>
<br>
    (Callback-&gt;RoutineBlock).Object = NULL;<br>
   
ExfReleaseRundownProtectionEx((&amp;(CallbackRoutineBlock-&gt;RundownProtect)),
((Value.RefCnt) + 1));<br>
    NewValue.Object =
(InterlockedCompareExchangePointer((&amp;(FastRef-&gt;Object)),<br>
                                                           
(NewValue.Object),<br>
                                                           
(Value.Object)));<br>
    for (((Entry = (Head-&gt;Flink)), (i = 0)); ((i &lt;
(Info-&gt;Depth)) &amp;&amp; ((Entry-&gt;Flink) != NULL)); ((i++),
(Entry = (Entry-&gt;Flink))))<br>
<br>
Looks like crap, doesn't it?<br>
<br>
You need to draw the line somewhere.<br>
IMO there's no use in adding parentheses around something when any
different parenthesing wouldn't make sense.<br>
You cannot mistake if (a &lt; 1 &amp;&amp; b &lt; 2) for if (a &lt; (1
&amp;&amp; b) &lt; 2) as the second doesn't make sense.<br>
<br>
Now I'd just like to see only one concrete example of when adding
parentheses around comparisons seperated by || / &amp;&amp; has an
advantage over not adding them.<br>
<br>
<br>
<br>
<br>
</body>
</html>


_______________________________________________
Ros-dev mailing list
Ros-dev@reactos.org
http://www.reactos.org/mailman/listinfo/ros-dev

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic