Last active
December 2, 2022 18:16
-
-
Save jmatth11/3a36a90fcde7dbed0a9dca9010579762 to your computer and use it in GitHub Desktop.
simple defer in C
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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