2

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 Answers1

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)\
}
unalignedmemoryaccess
  • 7,246
  • 2
  • 25
  • 40