I'm working on a debugging/logging program and was wondering if it would be possible to create a macro that I can paste inside each function and it will print the function name and parameter values each time the function's called. Function name can be resovled at compile time, the problem is figuring out how to print parameter values?
UPDATE: I remember reading an article to get parameters but that invovled assembly code and working manipulating stack pointers, which is not cross-platform compatible - something that I need.
You can use the __FUNCTION__
or __func__
macro for the function name. For the parameters, I don't think there's a built-in macro to achieve this.
Other helpful macros are __LINE__
and __FILE__
.
EDIT:
__FUNCTION__
and __func__
are not part of the standard, but they are widely supported.
16.8 deals with predefined macros:
__cplusplus
__DATE__
__FILE__
__LINE__
__STDC_HOSTED__
__TIME__
and macros defined by the implementation:
__STDC__
__STDC_VERSION__
__STDC_ISO_10646__
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With