Adding Prolog/Epilog

N

Neo

I want to log information for a function call like

void Add(void)
{

}

When above function gets called, it should output strings like

Entering Add
Exiting Add

So every function call should get logged. I want to add this
funcionality to each function I am going to write and it should get
added implicitly.
Can I create function prolog and epilogs? How to do that ? Is that
feasible?
 
D

dasjotre

Neo said:
I want to log information for a function call like

void Add(void)
{

}

When above function gets called, it should output strings like

Entering Add
Exiting Add

So every function call should get logged. I want to add this
funcionality to each function I am going to write and it should get
added implicitly.
Can I create function prolog and epilogs? How to do that ? Is that
feasible?

check http://www.research.att.com/~bs/wrapper.pdf
 
O

Ondra Holub

Neo napsal:
I want to log information for a function call like

void Add(void)
{

}

When above function gets called, it should output strings like

Entering Add
Exiting Add

So every function call should get logged. I want to add this
funcionality to each function I am going to write and it should get
added implicitly.
Can I create function prolog and epilogs? How to do that ? Is that
feasible?

You can simply create this class:
class LogEnterExit
{
public:
LogEnterExit(const char* fn): fn_(fn) { std::cout << "Entering " <<
fn << "\n"; }
~LogEnterExit() { std::cout << "Exitting " << fn_ << "\n"; }

private:
const char* fn_;
};

And then in your functions:
void Func()
{
LogEnterExit("void Func()");

// Your code
}

It is simple and has drawback in constructors. 'Entering' is written
after member initialization.
 
D

David Harmon

On 1 Dec 2006 06:48:08 -0800 in comp.lang.c++, "Ondra Holub"
And then in your functions:
void Func()
{
LogEnterExit("void Func()");

// Your code
}

Seems like that temporary would get destroyed sooner than you would
like.
 
O

Ondra Holub

David Harmon napsal:
On 1 Dec 2006 06:48:08 -0800 in comp.lang.c++, "Ondra Holub"


Seems like that temporary would get destroyed sooner than you would
like.

Yes, there is missing name of variable (I wrote it from scratch). It
shold be:

void Func()
{
LogEnterExit logger("void Func()");

// Your code
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,049
Latest member
Allen00Reed

Latest Threads

Top