- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
#include <stdio.h>
#include <stdlib.h>
void myfree(void *ptr)
{
printf("%p\n", *(void **)ptr);
free(*(void **)ptr);
printf("freed!\n");
}
int main(void) {
char *x __attribute__ (( cleanup (myfree) )) = malloc(1);
printf("%p\n", x);
return 0;
}
https://stackoverflow.com/questions/2053029/how-exactly-does-attribute-constructor-work
Ну т.е. в функцию void myfree(void *ptr) передается указатель на x. Можно переписать как-нибудь вот так:
The function must take one parameter, a pointer to a type compatible with the variable.
Или даже сделать чтоб:
#define MK_ARR(type, name, mallocfunc, freefunc, ...)
Чтоб кастомный аллокатор
Улучшил
Какой ____ )))
Это туда входит?