Created
August 28, 2012 16:04
-
-
Save YukiSakamoto/3499507 to your computer and use it in GitHub Desktop.
attribute(cleanup) sample
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> | |
#include <stdlib.h> | |
#define cleanup_free_scope __attribute__((cleanup(my_free))) | |
#define cleanup_print_scope __attribute__((cleanup(my_print_int))) | |
void my_print_int(int *i) | |
{ | |
printf("argument = %d\n", *i); | |
} | |
void my_free(void **p) | |
{ | |
printf("%p was freed.\n", p); | |
free(*p); | |
} | |
int main(void) | |
{ | |
void *p1 cleanup_free_scope = malloc(1000); | |
void *p2 cleanup_free_scope = malloc(128); | |
int val cleanup_print_scope = 10289; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment