4 ms·
How would the proposed solution work with this code? void foo() { char *p = malloc(...); defer free(p); ... { FILE *p = fopen(...);
by teo_zero 2y ago
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?
- gustedt 2y agoYes, 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.
- deleted 2y ago[deleted]