[Bro-Dev] #754: Complete implementation of switch statement

Bro Tracker bro at tracker.bro-ids.org
Thu Jan 10 08:54:51 PST 2013


#754: Complete implementation of switch statement
----------------------------+------------------------
  Reporter:  seth           |      Owner:  robin
      Type:  Merge Request  |     Status:  closed
  Priority:  Normal         |  Milestone:  Bro2.2
 Component:  Bro            |    Version:  git/master
Resolution:  fixed          |   Keywords:  language
----------------------------+------------------------

Comment (by jsiwek):

 > What are the semantics for "fall through"?  Are cases exclusive, or do
 they require something like "break" to prevent fall-through?  (I'm a fan
 of the former, but then you need a way of associating multiple labels with
 a single case-block.  For example, "case A, B, C: ..." rather than C-style
 "case A: case B: case C:".)

 Cases require a "break" to prevent fall-through, but it's not a hard
 change to make them exclusive.  At the time I didn't have a particular
 reason to do fall-through; it was just the most familiar behavior to me.
 What are advantages of making them exclusive?

 I can see that way being less error-prone because programmers can forget
 the "break" occasionally.  They're less flexible/powerful, though, right?
 E.g. this situation with fall-through:


 {{{
 switch ( v ) {
 case A:
     x();
 case B:
     y();
     z();
 }
 }}}

 would be equivalent without fall-through to either

 {{{
 switch ( v ) {
 case A, B:
     if ( v == A ) x();
     y();
     z();
 }
 }}}

 or

 {{{
 switch ( v ) {
 case A:
     x();
     y();
     z();
 case B:
     y();
     z();
 }
 }}}

 Meaning that situation needs duplicate code or that additional condition
 check without fall-through.    Any other preferences/thoughts on the
 tradeoffs?

-- 
Ticket URL: <http://tracker.bro-ids.org/bro/ticket/754#comment:22>
Bro Tracker <http://tracker.bro-ids.org/bro>
Bro Issue Tracker



More information about the bro-dev mailing list