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

How would the proposed solution work with this code?

  void foo() {
    char *p = malloc(...);
    defer free(p);
    ...
    {
      FILE *p = fopen(...);
      defer fclose(p);
      ...
    }
    return;
  }
Would it run both deferred statements, each with the correct argument?


Yes, the visibility rules for variables remain exactly the same. The dependent statement of a defer lives in the same scope as the defer is placed.




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

Search: