Created
April 15, 2015 14:44
-
-
Save jirfag/c9f65e6b2c31ea94d3b7 to your computer and use it in GitHub Desktop.
This file contains 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
#include <stdio.h> | |
#define TOKENPASTE(x, y) x ## y | |
#define TOKENPASTE2(x, y) TOKENPASTE(x, y) | |
#define UNIQUE_FUNC_NAME TOKENPASTE2(cleanuper_func_, __LINE__) | |
#define UNIQUE_VAR_NAME TOKENPASTE2(cleanuper_var_, __LINE__) | |
#define SCOPE_EXIT(code_) \ | |
void UNIQUE_FUNC_NAME(int *t __attribute__((unused))) \ | |
code_ \ | |
int UNIQUE_VAR_NAME __attribute__((cleanup(UNIQUE_FUNC_NAME))); | |
int main() | |
{ | |
SCOPE_EXIT({ printf("i'm in scoped exit 1\n"); }); | |
SCOPE_EXIT({ printf("i'm in scoped exit 2\n"); }); | |
printf("i'm before return\n"); | |
return 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment