/* -*- Mode: C; -*- * ---------------------------------------------------------------------------- * Title: unwind_protect macro * Created: 2020-05-24 * Author: Gilbert Baumann * ---------------------------------------------------------------------------- * (c) copyright 2020 by Gilbert Baumann */ #include #include #define unwind_protect(body, cleanup) \ do{ \ void uwp_cleanup (void *uwp_p) \ { \ (void)uwp_p; \ { cleanup; } \ } \ int uwp_dummy \ __attribute__ ((__cleanup__ (uwp_cleanup))); \ { body; } \ }while(0) void foo (void) { unwind_protect ({ printf ("hi, there\n"); return; }, { printf ("cleanup\n"); }); } int main (int argc, char **argv) { (void)argc; (void)argv; foo (); return 0; }