Conversation
Notices
-
Embed this notice
✿ xX_Аня_Xx ✿ (fence@xyzzy.link)'s status on Thursday, 18-Jul-2024 19:26:51 JST ✿ xX_Аня_Xx ✿ C(Programing Language)rimes - snacks likes this.
-
Embed this notice
✿ xX_Аня_Xx ✿ (fence@xyzzy.link)'s status on Thursday, 18-Jul-2024 19:38:11 JST ✿ xX_Аня_Xx ✿ @mia nooooo stop it snacks likes this. -
Embed this notice
miauz genyau (mia@movsw.0x0.st)'s status on Thursday, 18-Jul-2024 19:38:13 JST miauz genyau @fence i love doing Crimes
you can have golang defer in C:
#include #include #include #define DEFER_INIT \ __label__ _lk_defer_exec; \ int _k_defer_exec = 0; \ size_t _k_ndefers = 0; \ void* _k_defers[16]; \ #define DEFER_EXEC \ _lk_defer_exec: \ _k_defer_exec = 1; \ if (_k_ndefers) \ goto *_k_defers[--_k_ndefers]; \ #define defer(x) \ do { \ __label__ _lk_defer; \ _lk_defer: \ if (_k_defer_exec) { \ x; \ goto _lk_defer_exec; \ } else { \ _k_defers[_k_ndefers] = &&_lk_defer; \ _k_ndefers++; \ } \ } while (0) void testfunc(void) { DEFER_INIT char* foo = malloc(6); memcpy(foo, "defer", 6); defer(free(foo); foo = NULL); printf("foo: %s\n", foo); DEFER_EXEC printf("foo: %s\n", foo); } int main(void) { DEFER_INIT testfunc(); defer(printf("world\n")); defer(printf("hello ")); DEFER_EXEC }