|
BDE 4.14.0 Production release
|
Macros | |
| #define | BSLA_FALLTHROUGH |
Provide a macro to suppress warnings on switch fall-throughs.
switch case falls throughBSLA_FALLTHROUGH is activeThis component provides a preprocessor macro that suppresses compiler warnings about flow of control fall-through from one case or default of a switch statement to another. On compilers where the appropriate attribute is not supported, the macro expands to nothing.
BSLA_FALLTHROUGH: This annotation should be placed in a case clause as the last statement within a flow of control that is expected to allow control to fall through instead of ending with a break, continue, or return. This will prevent compilers from warning about fall-through. The BSLA_FALLTHROUGH must be followed by a semicolon and may be nested within blocks, ifs, or elses.
BSLA_FALLTHROUGH_IS_ACTIVE: The macro BSLA_FALLTHROUGH_IS_ACTIVE is defined if BSLA_FALLTHROUGH expands to something with the desired effect; otherwise BSLA_FALLTHROUGH_IS_ACTIVE is not defined and BSLA_FALLTHROUGH expands to nothing.
This section illustrates intended use of this component.
First, we define a function:
Then, we have a switch in the function:
Next, we see that BSLA_FALLTHROUGH; as the last statement in a case block before falling through silences the fall-through warning from the compiler:
Then, we see this also works on cases that don't have a {} block:
Next, we see that a BSLA_FALLTHROUGH; works within an if block, provided that it's in the last statement in the flow of control before falling through:
Now, we see that a BSLA_FALLTHROUGH; can also occur as the last statement in an else block:
Finally, we see that if we compile when BSLA_FALLTHROUGH_IS_ACTIVE is set, the above compiles with no warnings.
| #define BSLA_FALLTHROUGH |