I'm trying to add some debugging facility to my application and now stuck with using static inline
function. As I learnt from this answer it was possible to put static inline
function definition into a header file so function is not instantiated twice in case the file is included multiple times.
So I was curious and tried to define the similar static inline
function for tracing invokation and put it into a header file:
#ifndef TRACE_H
#define TRACE_H
static inline void trace(){
printf("Current line %d, func %s, file %s\n", __LINE__, __func__, __FILE__);
}
#endif //TRACE_H
I tried this because static inline
is much less error-prone then macro. The problem is that the simple
int main(int argc, char const *argv[])
{
trace();
}
prints Current line 8, func trace, file /home/somename/include/trace.h
which is obviously useless.
So for tracing purpose is there any other way unless to define the macro
#define trace() \
printf("Current line %d, func %s, file %s\n", __LINE__, __func__, __FILE__); \