Jump to content
  • Advertisement
Sign in to follow this  
REspawn

[C++] Logging function arguments

This topic is 2716 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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







Share this post


Link to post
Share on other sites
Advertisement

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:


  • boost::function_types
  • The boost preprocessor library to generate functions with different arity overloads
  • C++11 variadic templates
  • Some 'clever' variadic macro usage


    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.

Share this post


Link to post
Share on other sites
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.




Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

[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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!