| ▲ | akoboldfrying 2 hours ago | |
In C++ you can implement such a thing using destructors, which are guaranteed to run in reverse order on scope exit even in the presence of exceptions. Alexei Alexandrescu's Scopeguard did this (in the 90s I think, long before C++11). But in standard C, there's no mechanism that this could be attached to (especially if you want to use "C exceptions", a.k.a. setjmp()/longjmp()). Maybe the compilers they support all have non-standard extensions that allow something like this though? | ||
| ▲ | shakna an hour ago | parent [-] | |
Yes, because all compilers support a non-standard defer mechanism, its now being considered for inclusion into standard C. [0] And that suggested defer standard, is already available from GCC 9 and clang 22. [0] https://www.open-std.org/JTC1/SC22/WG14/www/docs/n3734.pdf | ||