switch case for constants-only?

Nick Sabalausky a at a.a
Sat Dec 5 14:59:13 PST 2009


"Rainer Deyke" <rainerd at eldwood.com> wrote in message 
news:hfenkl$veq$1 at digitalmars.com...
> Nick Sabalausky wrote:
>> As I mentioned earlier, that should be semantically equivilent to:
>>
>> int x = 1, y = 1;
>>
>> if(z == x)
>> { ... }
>> else if(z == y)
>> { ... }
>>
>> In fact, it's already semantically equivilent to that, except that x and 
>> y
>> are currently required to be known at compile-time.
>
> I assume the same rule applies to 'goto case'?
>
> int i = 0, j = 0;
> switch (0) {
> case i:
>  goto case j; // Oops, infinite loop.
> case j:
>  // Never reached.
> }
>
> I'm basically in favor of this change - it increases the expressive
> power and uniformity of the language at little cost - but corner cases
> like this bother me.
>

I think that amounts to a computed goto, which I don't think D currently 
has, so that probably just wouldn't compile.

But with or without computerd goto, this sounds like a reason to use an 
actual fallthrough command instead of "goto case".





More information about the Digitalmars-d mailing list