Created
June 12, 2022 12:28
-
-
Save mu8086/c3316530397926647a4f2c12936b3a34 to your computer and use it in GitHub Desktop.
[C] variadic free function
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
void doFree(void * allocate, ...) { | |
void *target = allocate; | |
va_list args; | |
va_start(args, allocate); | |
while (target != NULL) { | |
free(target); | |
target = va_arg(args, void *); | |
} | |
va_end(args); | |
} | |
void main(void) { | |
char *a = (char *) malloc(sizeof(char)); | |
int *b = (int *) malloc(sizeof(int)); | |
doFree(a, b, NULL); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment