[comp.lang.c] switch

weisen@eniac.seas.upenn.edu) (Neil I. Weisenfeld ;-) (12/23/89)

It's been a while since this happened so I don't have the code lying
around, but....

I am using gcc v1.35 under DEC's ULTRIX.  I was diligently working on
a project that was due the next morning when quite a bit of my time
was taken up trying to find a really weird bug.  As it turns out, I
misspelled `default' as `defualt' in a switch statement.  The code
compiled without an error, however the `defualt' was never executed;
it just dropped out of the switch.  Is this a bug or is there a
rational `C' explanation for this?


Neil


-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
   #              ##    Neil Weisenfeld        | Internet:
  ###               #   Univ. of Pennsylvania  | weisen@eniac.seas.upenn.edu
   #                 #  Computer Science Dept. | 
         #####       #  Class of 1991          | 
   #                 #                         | USPS:                    
  ###               #   <-giant killer         | 3700 Spruce St., Box 572 
   #              ##      net-smile            | Philadelphia, PA  19104  
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

cpcahil@virtech.uucp (Conor P. Cahill) (12/23/89)

In article <18472@netnews.upenn.edu>, weisen@eniac.seas.upenn.edu) (Neil I. Weisenfeld ;-) writes:
> I am using gcc v1.35 under DEC's ULTRIX.  I was diligently working on
> a project that was due the next morning when quite a bit of my time
> was taken up trying to find a really weird bug.  As it turns out, I
> misspelled `default' as `defualt' in a switch statement.  The code
> compiled without an error, however the `defualt' was never executed;
> it just dropped out of the switch.  Is this a bug or is there a
> rational `C' explanation for this?

This will happen in any C compiler.  Since the defualt does not 
match "default" it is then interpreted as a label (used by goto's).  So
your defualt: code would be executed as part of the preceding case.

If you had linted the code, you would have gotten a message about
defualt being unused.  This would have pointed out the problem to you.
-- 
+-----------------------------------------------------------------------+
| Conor P. Cahill     uunet!virtech!cpcahil      	703-430-9247	!
| Virtual Technologies Inc.,    P. O. Box 876,   Sterling, VA 22170     |
+-----------------------------------------------------------------------+

weisen@eniac.seas.upenn.edu) (Neil I. Weisenfeld ;-) (12/24/89)

Thanks to all those who gave me (non-obnoxious) replies to my posting.
I didn't realize that gcc would interpret `defualt' in a case xxx: as
a label if it hadn't been defined.  Is this non-ANSI C not to give an
error for undefined and un-prototyped symbols.

Neil


-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
   #              ##    Neil Weisenfeld        | Internet:
  ###               #   Univ. of Pennsylvania  | weisen@eniac.seas.upenn.edu
   #                 #  Computer Science Dept. | 
         #####       #  Class of 1991          | 
   #                 #                         | USPS:                    
  ###               #   <-giant killer         | 3700 Spruce St., Box 572 
   #              ##      net-smile            | Philadelphia, PA  19104  
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

cpcahil@virtech.uucp (Conor P. Cahill) (12/24/89)

In article <18485@netnews.upenn.edu>, weisen@eniac.seas.upenn.edu) (Neil I. Weisenfeld ;-) writes:
> Thanks to all those who gave me (non-obnoxious) replies to my posting.
> I didn't realize that gcc would interpret `defualt' in a case xxx: as
> a label if it hadn't been defined.  Is this non-ANSI C not to give an
> error for undefined and un-prototyped symbols.

How does one define or prototype a statement label?

Interpreting "defualt" as a statement label is correct in all versions of C.
-- 
+-----------------------------------------------------------------------+
| Conor P. Cahill     uunet!virtech!cpcahil      	703-430-9247	!
| Virtual Technologies Inc.,    P. O. Box 876,   Sterling, VA 22170     |
+-----------------------------------------------------------------------+