问题
How can I replace all occurence of
check_free_set_to_null(&pointer)
by
if (pointer)
{
free(pointer)
printf(pointer have been freed)
}
else
{
printf(pointer couldnt had been freed)
return (1)
}
maybe using some sort of
{1} = check_free_set_to_null(CONTENT)
if ({1})
{
free({1})
printf({1} have been freed)
}
else
{
printf({1} couldnt had been freed)
return (1)
}
how could I do that ? (take note thats its not exactly what that have to be replaced, its just an example) Im not looking for the compiler to interpret it as multiple line, im looking for modifying the file.
回答1:
You can use macros for this job.
#define check_free_set_to_null(pointer) if (pointer) { \
free(pointer)\
printf(pointer have been freed)\
} else {\
printf(pointer couldnt had been freed)\
return (1)\
}
来源:https://stackoverflow.com/questions/44869388/replace-function-or-define-by-the-text-itself