4 ms·
Adding a statement that would require a dynamic allocation for every iteration of a loop is kind of insane for C. It doesn't matter what the defer does, if it'
by knome 5y ago
Adding a statement that would require a dynamic allocation for every iteration of a loop is kind of insane for C.
It doesn't matter what the defer does, if it's allocated in a for statement and doesn't go off until the surrounding function exits, then it's going to have to stuff tons of function pointers and parameters somewhere, presumably alloca'd onto the stack over and over.
That's not C. That shouldn't be C.
There are a dozen languages for doing clever dynamic magical things in code. C is still fairly straightforward. Use one of the other languages instead of bagging down C with complexity until it turns into another difficult C++ variant over time.