how to freeing pointers using macro in c

前端 未结 5 636
我寻月下人不归
我寻月下人不归 2021-01-16 06:26

I want to write macro in c code to freeing many pointers like this :

FREE(ptr1, ptr2, ptr3, ptr4, ptrx);

For me, this is better than

5条回答
  •  暖寄归人
    2021-01-16 06:35

    Maybe you can define a function like:

    void freeargs(void *ptr1, ...) {
        // code for freeing variable number of arguments until NULL pointer.
    }
    

    and then the macro:

    #define FREE(...) freeargs(__VA_ARGS__, NULL)
    

提交回复
热议问题