Thread overview
switch statement under debug - (0.88) windows
May 10, 2004
Russell
May 10, 2004
J Anderson
May 10, 2004
J C Calvarese
May 10, 2004
If you define a switch statement and don't have a default it exe will compile ok for debug and release.  The release version runs ok but the debug version throws an error saying 'switch with no default' which is not what I would expect.  Also if you do this in a static lib it causes a windows violation and crashes the program.

I don't believe switch without a default is/should be an error and the behaviour between debug and release should be consistant, maybe a warning during compile?

Russell


May 10, 2004
Russell wrote:

>If you define a switch statement and don't have a default it exe will compile ok
>for debug and release.  The release version runs ok but the debug version throws
>an error saying 'switch with no default' which is not what I would expect.  
>
Walter believes that in the general case, all cases should be handled in a debug statement.  This run-time check is useful for finding cases where you forgot to check for a particular case.

>Also
>if you do this in a static lib it causes a windows violation and crashes the
>program.
>  
>
Doesn't it crash the program anyway?  Your not trying to catch the exception are you?

>I don't believe switch without a default is/should be an error and the behaviour
>between debug and release should be consistant
>  
>
The idea of debug mode is enable more complex testing at the cost of runtime performace / file size / memory usage. Therefore it would be a bad idea to have this debug test in release mode.

>maybe a warning during compile?
>

Walters anti-warning.  There are no warnings in D.

>Russell
>
-- 
-Anderson: http://badmama.com.au/~anderson/
May 10, 2004
Russell wrote:
> If you define a switch statement and don't have a default it exe will compile ok
> for debug and release.  The release version runs ok but the debug version throws
> an error saying 'switch with no default' which is not what I would expect.  Also
> if you do this in a static lib it causes a windows violation and crashes the
> program.
> 
> I don't believe switch without a default is/should be an error and the behaviour
> between debug and release should be consistant, maybe a warning during compile?
> 
> Russell

Unfortunately, this is as Walter intends. I'd prefer a compile-time error on a missing default to the current mess, but I haven't written the compiler.

Since I'm used to BASIC, I don't like the fallthrough nature of switch either. But the occasional runtime error for an unspecified case drives me crazy!

-- 
Justin (a/k/a jcc7)
http://jcc_7.tripod.com/d/