About switch case statements...

Walter Bright newshound1 at digitalmars.com
Mon Nov 16 14:20:53 PST 2009


Denis Koroskin wrote:
> BTW, if a macro was declared as
> 
> #define BASIC_TYPES            \
>          TOKwchar: case TOKdchar:        \
>     case TOKbit: case TOKbool: case TOKchar:    \
>     case TOKint8: case TOKuns8:        \
>     case TOKint16: case TOKuns16:        \
>     case TOKint32: case TOKuns32:        \
>     case TOKint64: case TOKuns64:        \
>     case TOKfloat32: case TOKfloat64: case TOKfloat80:        \
>     case TOKimaginary32: case TOKimaginary64: case TOKimaginary80:    \
>     case TOKcomplex32: case TOKcomplex64: case TOKcomplex80:    \
>     case TOKvoid
> 
> (note an absence of the first case) then it would cause compile-time 
> error instead of run-time bugs. Usage:
> 
> switch (token) {
>     case TOKidentifier:
>     case TOKenum:
>     case TOKstruct:
>     case TOKimport:
>     case BASIC_TYPES:
> }

I like that. Great suggestion!



More information about the Digitalmars-d mailing list