Jump to content
  • Advertisement
Sign in to follow this  
Prozak

C++ Trick I can't remember...

This topic is 3552 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

Does anyone know that C++ trick that allowed us to code a function that would be called each time we called a function? Let me explain, in a normal program, Function A calls Function B. Using this system, A would call our pre-defined code, and then B. From what I remember some people used it as a tracer... Any ideas?

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by Prozak
Does anyone know that C++ trick that allowed us to code a function that would be called each time we called a function?

Let me explain, in a normal program, Function A calls Function B. Using this system, A would call our pre-defined code, and then B.

From what I remember some people used it as a tracer...

Any ideas?
It doesn't work exactly like you specify, but in MSVC there is _penter and _pexit which are inserted in the beginning and end of each function, such that the sequence would be
Function A's Code -> Function B -> _penter -> Function B's Code -> _pexit -> Back to Function A's Code

The distinction from what you said is that the calls to _penter and _pexit are inserted inside function B, so if function B is inside a library that was compiled with different settings, _penter and _pexit will not be called.

Share this post


Link to post
Share on other sites
Replace function B with a class where function B is the ()operator. pre call code would go in the constructor post call code would go in the destructor.

Share this post


Link to post
Share on other sites
Link.

Not sure if it's what you want exactly, but you might find it interesting anyway.

[Edited by - Gage64 on October 24, 2008 12:30:21 PM]

Share this post


Link to post
Share on other sites
Similar to the MSVC suggestion from above, gcc supports -finstrument-functions, which will generate calls to user-defined prologue/epilogue functions for every function.

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!