On 27-07-2012 05:32, Ali Çehreli wrote:
On 07/26/2012 06:58 PM, Stuart wrote:
 > On Friday, 27 July 2012 at 00:23:54 UTC, Ali Çehreli wrote:

 > Well, kinda. "Goto case" and such are one thing, but allowing the
 > arbitrary use of goto for jumping around from label to label.... I just
 > don't understand why the language even supports this.

Unlike C++, the language disallows unsafe jumping forward (or is it dmd
that disallows it?). Hmmm... Maybe I am wrong... (?) I swear, the
following code used to generate a compilation error:

     if (aCondition) {
         goto label;    // Jumps over s's constructor call
     }

     auto s = S(7);

label:

     s.foo();

The error used to say:

   "Error: cannot goto forward into different try block level."

The code is allowed by dmd 2.059.

The code is allowed for classes as well but of course there is a
segmentation faault due to foo() on the null object. Strange...

 > Anyone using 'goto
 > label' in their code is doing it wrong. Period.

I agree.

Ali


Jumping over initialization isn't as problematic in D because variables are guaranteed to have a default initialization value (if not initialized to void). It's worse in languages like C where the value of variables would be undefined.

--
Alex Rønne Petersen
a...@lycus.org
http://lycus.org

Reply via email to