You use macros to do what? Please read
<
http://cfaj.freeshell.org/google/>. Google's posting interface is
badly broken, but it can be used correctly with just a little extra
effort.
#include <stdio.h>
#define perform_action(a) _perform_action((a),__FILE__,__LINE__)
void _perform_action(int actCd, const char * file, int lineno);
Avoid identifiers with leading underscores. Many of them are reserved
for use by the implementation. Rather than memorizing or looking up
the rules for which ones are reserved in which contexts, it's best to
just avoid them altogether (unless you're using something defined for
you by the implementation).
If you want to generate an identifier from an existing one, trailing
underscores are ok.
void _perform_action(int actCd, const char * file, int lineno) {
printf("Called perform_action from %s:%d\n", file, lineno);
}
int main(void) {
perform_action(4);
return 0;
}
Otherwise, that looks reasonable. It's a lot of extra work, it only
goes up one level (going up arbitrarily many levels is going to be
interesting), and it only works for functions for which you
specifically provide the feature.
The most likely reason you'd want this information is for debugging.
In that case, a good source-level debugger should give you that
information and a lot more as well. If you want the behavior of the
function to vary depending on where it's called from, that's almost
certainly a bad idea, better implemented by just passing an extra
argument to control the behavior.
As with a lot of low-level stuff like this, the first thing you should
do is step back and decide what problem you're actually trying to
solve. It's likely that there's a better and/or more portable
solution.