| Thread overview | |||||
|---|---|---|---|---|---|
|
September 16, 2014 switch statement exiting a void function | ||||
|---|---|---|---|---|
| ||||
Here's the setup, I have a function
void main { ... }
The main method parses input (via std.getopt) and calls one of three void-return-type functions. The program's three options correspond to significantly different initialization options.
In the code we then have:
enum RunOpt {opt1, opt2, opt3};
And the body of the function wants to do:
RunOpt option;
//parsing that results in, among other things option being initialized
switch(option){
case RunOpt.opt1: fun1(...);
case RunOpt.opt2: fun2(...);
default: fun3(...);
}
When compiling, the error I get is
Error: switch case fallthrough - use 'goto case;' if intended
This is not intended. Note that calling "return;" after "funi(...)" makes everything work. However, it feels like I'm doing something wrong here?
| ||||
September 16, 2014 Re: switch statement exiting a void function | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Jonathan | Jonathan:
> This is not intended. Note that calling "return;" after "funi(...)" makes everything work. However, it feels like I'm doing something wrong here?
Try:
enum RunOpt { opt1, opt2, opt3 } // No semicolon here
final switch (option) with (RunOpt) {
case opt1: fun1(...); break;
case opt2: fun2(...); break;
case opt3: fun3(...); break;
}
Bye,
bearophile
| |||
September 16, 2014 Re: switch statement exiting a void function | ||||
|---|---|---|---|---|
| ||||
Posted in reply to bearophile | > Try:
>
> enum RunOpt { opt1, opt2, opt3 } // No semicolon here
>
> final switch (option) with (RunOpt) {
> case opt1: fun1(...); break;
> case opt2: fun2(...); break;
> case opt3: fun3(...); break;
> }
>
> Bye,
> bearophile
My hero.
| |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply