[C++] Logging function arguments

Started by
7 comments, last by gekko 12 years, 11 months ago
Hi,

Does anyone know of a macro or easy way to loop through a functions arguments in C++? I'm not talking about variable arguments, just the normal fixed ones.

Thanks for any help,

Dave







Advertisement
It can't be done. Why do you think you need this?

Does anyone know of a macro or easy way to loop through a functions arguments in C++? I'm not talking about variable arguments, just the normal fixed ones.

What are variable and fixed arguments?

Depending on what you want to do exactly, you might be able to use one of these:



It is probably worth mentioning explicitly what you're trying to achieve in broader terms as someone may have a better solution for your problem than iterating over arguments.
Thanks for the reply guys. My end goal would be in the debug build to log all arguments passed into a function. For profiling purposes.





Thanks for the reply guys. My end goal would be in the debug build to log all arguments passed into a function. For profiling purposes.


Why wouldn't normal logging of the parameters work here? Even with extreme templatization, most logging procedures should do the trick.

[quote name='REspawn' timestamp='1303942651' post='4803738']
Thanks for the reply guys. My end goal would be in the debug build to log all arguments passed into a function. For profiling purposes.


Why wouldn't normal logging of the parameters work here? Even with extreme templatization, most logging procedures should do the trick.
[/quote]

It would. I was just researching to see if there was a nice macro / template way to do this. So all you had to do was stick macro at the top of each function and it would work regardless of the number of arguments.
pre-processing the source with your own script
or using some other metaobject compiler might be the 'cleanest' choice

variadic macros probably won't be pretty:
http://stackoverflow...variadic-macros
http://cplusplus.co....r-of-arguments/
https://gustedt.word...acro-arguments/
Thanks aqrit, I'll check them out.
You can do it with symbol information, same way that debuggers can print out the information in the call stack window. If you're using Windows and Visual Studio, check out the DbgHelp functions. I wouldn't recommend it for profiling purposes, since accessing symbol information is slow, but I wouldn't recommend logging at all during profiling.
-- gekko

This topic is closed to new replies.

Advertisement