News for hackers. Stuff that matters.
Re:Windows File Manager re-released by cr0sh on Thursday September 05, 2019 @06:49PM (#20891344)
Found a C "goto" in that code, too - eek. Maybe there was a good reason...
Re:Windows File Manager re-released by Narishma on Thursday September 05, 2019 @07:13PM (#20891477)
There's nothing wrong with goto in C.
Re:Windows File Manager re-released by presidentscroob on Friday September 06, 2019 @04:18AM (#20893952)
It's a good pattern to DRY-up resource-releasing unwind code. In an ideal world, there would be closures, RAII and fluent interfaces (macros) that would wrap allocation, deallocation, error and success handling without needing C++ and avoiding resource leaks.

    int
    some_func(void) {
      int result = ERR;

      HANDLE foo = alloc_foo();
      if (!foo) goto err0;

      HANDLE bar = alloc_bar();
      if (!bar) goto err1;

      if (do_something_else() < 0) goto err2;

      result = OK;
    err2:
      release_bar(bar);
    err1
      release_foo(foo);
    err0:
      return result;
    }
Re:Windows File Manager re-released by yitchelle on Friday September 06, 2019 @04:27AM (#20893989)
As with everything in C, it must be used with care and thought. It can come back and bite you in the future if use frivolously.
Re:Windows File Manager re-released by ben_bai on Friday September 06, 2019 @06:03AM (#20894371)
Nothing wrong with using goto, sparingly. It's the preferred way for error handling in C.

Nobody has code like this anymore

    10 I=1
    20 PRINT "HELLO "
    40 PRINT %I
    50 IF (%I > 3) 10 40
    30 PRINTLN "WORLD"
    45 PRINTLN
    42 I=%I+1
Notice no goto statement, yet lots of implicit gotos.
Re:Windows File Manager re-released by cjarrett on Friday September 06, 2019 @11:43AM (#20896651)
What about a Goto within a switch statement that's within another switch statement in a function that's 3000 lines long?