[DGD] Switch-Case Variable Scope
Raymond Jennings
shentino at gmail.com
Tue May 19 20:03:15 CEST 2015
Plus you can always do this:
switch(foo)
{
case foo:
{ /* Create a block inside a case label, like this */
blah blah blah;
}
}
I do this quite often myself.
On Thu, Apr 18, 2013 at 9:51 AM, Felix A. Croes <felix at dworkin.nl> wrote:
> 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
> ____________________________________________
> https://mail.dworkin.nl/mailman/listinfo/dgd
>
More information about the DGD
mailing list