Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

GOTO is still perfectly acceptable and common practice in the Linux kernel and other widely used codebases.

https://www.kernel.org/doc/html/v5.0/process/coding-style.ht...



If anyone is curious, it's not just used to make unreadable spaghetti code. There are certain common paradigms, eg.

  int do_stuff_in_order(void) {
      int ret = init_a();
      if (ret != success) goto out;

      ret = init_b();
      if (ret != success) goto error1;

      ret = init_c();
      if (ret != success) goto error2;

      return 0;

      error2:
      teardown_b();

      error1:
      teardown_a();

      out:
      return ret;
  }




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: