Remix.run Logo
ori_b 5 days ago

You can also have some kind of heapify/free, with undefined behavior if you get it wrong.

I think the C standards committee needs to figure out memory safety before adding any new features that are likely to interact with it.

PaulHoule 5 days ago | parent [-]

So you're saying the runtime mallocs the pointer to the closure and it's your responsibility to free it when you don't need it anymore?

ori_b 5 days ago | parent [-]

Kinda. Here's an example:

     void
     mkclosure(int x)
     {
         int x;
         void fn(void){ return x + 1; }
         return fnheapify(fn);
     }

     void
     useclosure(void)
     {
         void (^fn)(void) = mkclosure(42);
         fn();
         fnfree(fn);
     }