News:

Simutrans Sites
Know our official sites. Find tools and resources for Simutrans.

Parenthesis in grund.cc

Started by gerw, May 22, 2009, 07:19:37 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

gerw

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.

prissi

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.

Dwachs

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) );
Parsley, sage, rosemary, and maggikraut.

prissi

Those are the intended (and need to go also on the other direction then ...