Skip to content

Instantly share code, notes, and snippets.

@jmatth11
Last active December 2, 2022 18:16
Show Gist options
  • Save jmatth11/3a36a90fcde7dbed0a9dca9010579762 to your computer and use it in GitHub Desktop.
Save jmatth11/3a36a90fcde7dbed0a9dca9010579762 to your computer and use it in GitHub Desktop.
simple defer in C
#define macro_var(name) name##__LINE__
#define defer(start, end) for ( \
int macro_var(_i_) = (start, 0); \
!macro_var(_i_); \
(macro_var(_i_) += 1), end) \
/**
Example usage:
defer(open(), close())
{
// other code.
}
**/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment