[DGD] Switch-Case Variable Scope
Felix A. Croes
felix at dworkin.nl
Thu Apr 18 18:51:04 CEST 2013
Blain <blain20 at gmail.com> wrote:
> Well, because this is the first time I've seen a block placed there! In
> all my years... I wonder if I missed this in other drivers too. Yup,
> LPMUD/Amylaar allows it. MudOS allows it without braces, which is where I
> was spoiled from. Even in LPMUD and LDMUD docs I'd never seen an example
> of using a block specifically with a case label. Thanks!
DGD's dialect of LPC follows C89, which does not allow mixing of
declarations and code. This goes against recent programming language
trends, but in my opinion, separate declarations make for clearer code.
C99 and C++ allow mixing declarations and code. The scope of each
declaration is until the end of the statement block (including a switch
statement block).
Your example:
> switch(typeof(arg))
> {
> case T_ARRAY:
> mixed *ret;
>
> <code>
> break;
> cade T_MAPPING:
> mapping ret;
>
> <code>
> break;
> }
has a variable declared twice in the same statement block. I'm surprised
that MudOS allows this; separate scoping for case-labelled code is
definitely not part of the general trend. Certainly, this is a good
example of the sort of confusion that I want to prevent.
Regards,
Felix Croes
More information about the DGD
mailing list