Modify printf()s via macro to include file and line number information

c

Solution

With the caveat in my comment, you could do it using a variadic macro:

#define PRINTF_FL(format, ...) \
    printf(format " %s %d", __VA_ARGS__, __FILE__, __LINE__)

Problem

I was just wondering if there is some macro-hack we can use, to alter existing printf() statements in a project. ``` /* file.c */ printf ("%s", strerror(errno)); /* After macro processing, this line would become */ printf ("%s %s %d", strerror(errno), __FILE__, __LINE__); ```

Original source