I have some questions regarding the void pointer in C. I found out the following code, part of ffmpeg, which I could not understand ... Can someone explain to me how this works?
void av_freep(void *arg)
{
void *val;
memcpy(&val, arg, sizeof(val));
memcpy(arg, &(void *){ NULL }, sizeof(val));
av_free(val);
}
and then it is called like this:
char *str;
av_freep(&str);
my questions:
- how does the passed str (& str) address not cause a "incompatible type" warning when compiling it? Should type & str become char **?
- What is the value of & (void *) {NULL} in one of the memcpy parameters?
- why is he trying to free a "val" that is not allocated?
Thank!
source
share