The question is: is it possible in C to get the name of the module (header) from which the function is called (and in which it is described)?

For example:

//simple.h void foo(); //simple.c void foo(){} //main.c #include "simple.h" char name[] = getModuleName(foo()); printf("%s", name); // simple 

    1 answer 1

    No problem.

    For example, in the macro

     #define DEBUG(l,e,t) \ ((e) ? \ 0 \ : debug_message(l, __STRING(e), t, __FILE__, __LINE__, __FUNCTION__)) 

    to the debug_message() function are passed

    • argument 1;

    • the second argument (usually a logical expression) in string form;

    • the name of the file in which DEBUG called;

    • line number in this file;

    • the name of the function from which DEBUG is called