The International Simutrans Forum

Development => Patches & Projects => Incorporated Patches and Solved Bug Reports => Topic started by: gerw on May 22, 2009, 07:19:37 PM

Title: Parenthesis in grund.cc
Post by: gerw on May 22, 2009, 07:19:37 PM
Is the parenthesis in line 603 wilfully placed as it is?

fence_west = (flags&has_way1)==0  ||  (static_cast<weg_t*>(obj_bei(0))->get_ribi_unmasked()&ribi_t::west)==0
&& ( (flags&has_way2)==0  ||  (static_cast<weg_t *>(obj_bei(1))->get_ribi_unmasked()&ribi_t::west)==0);


I and my complier would prefer (since && has precedence before ||)

fence_west = ( (flags&has_way1)==0  ||  (static_cast<weg_t*>(obj_bei(0))->get_ribi_unmasked()&ribi_t::west)==0 )
&& ( (flags&has_way2)==0  ||  (static_cast<weg_t *>(obj_bei(1))->get_ribi_unmasked()&ribi_t::west)==0);


However, the code seems to be ok.
Title: Re: Parenthesis in grund.cc
Post by: prissi on May 24, 2009, 08:06:50 PM
Actually, if no way1 is there there will be no way2. Using short curcuit evaluation the evaluation will without extra paranthese stop after way1==0; with parentheses it will always have to check for way2, even if way1 is not there.
Title: Re: Parenthesis in grund.cc
Post by: Dwachs on May 25, 2009, 07:30:33 PM
what about this:

fence_west = (flags&has_way1)==0  ||
             ( (static_cast<weg_t*>(obj_bei(0))->get_ribi_unmasked()&ribi_t::west)==0 &&
               ( (flags&has_way2)==0  ||  (static_cast<weg_t >(obj_bei(1))->get_ribi_unmasked()&ribi_t::west)==0) );
Title: Re: Parenthesis in grund.cc
Post by: prissi on May 25, 2009, 07:58:26 PM
Those are the intended (and need to go also on the other direction then ...