|
|
|
|
|
by eps
1609 days ago
|
|
> block scoped defer That's the thing. Block-scoped is a better option as far as the language "spirit" is concerned, but it's limiting (see below). Function-scoped is more useful, but when used in loops it may lead to unbound stack usage and that sorta goes against the rest of C, because no other _language construct_ comes with such lovely side effect. Re: limiting - It's not uncommon for a function to need to grab some resource conditionally and then use it in the rest of the function code, e.g. void foo()
{
bar * b = NULL;
if (x && y)
{
this();
b = that();
}
...
baz(1, 2, b); // b may be null
...
release(b);
}
This can't be handled with block-scope defers. This needs function-scoped ones.A better option would (probably) be to allow binding defers to a specific on-stack variable... but that's basically a destructor and that opens its own can of worms, not all of which as technical. |
|