Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Adding Prolog/Epilog

Reply
Thread Tools

Adding Prolog/Epilog

 
 
Neo
Guest
Posts: n/a
 
      12-01-2006
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?

 
Reply With Quote
 
 
 
 
dasjotre
Guest
Posts: n/a
 
      12-01-2006

Neo wrote:
> 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

 
Reply With Quote
 
 
 
 
Ondra Holub
Guest
Posts: n/a
 
      12-01-2006

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.

 
Reply With Quote
 
David Harmon
Guest
Posts: n/a
 
      12-01-2006
On 1 Dec 2006 06:48:08 -0800 in comp.lang.c++, "Ondra Holub"
<> wrote,
>And then in your functions:
>void Func()
>{
> LogEnterExit("void Func()");
>
> // Your code
>}


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

 
Reply With Quote
 
Ondra Holub
Guest
Posts: n/a
 
      12-01-2006

David Harmon napsal:
> On 1 Dec 2006 06:48:08 -0800 in comp.lang.c++, "Ondra Holub"
> <> wrote,
> >And then in your functions:
> >void Func()
> >{
> > LogEnterExit("void Func()");
> >
> > // Your code
> >}

>
> 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
}

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Question: Adding Wireless to a Hard-Wired Home Office (w/Web & Email) Nick Knight Wireless Networking 2 01-06-2005 03:46 AM
Adding an Antenna Pigtail to a WiFi card Guy Smith Wireless Networking 0 12-31-2004 11:15 AM
Adding Linksys or Dlink into a Microsoft networking product config =?Utf-8?B?c2tsZWZmbg==?= Wireless Networking 0 12-03-2004 04:12 PM
RE: Adding laptop to a new network =?Utf-8?B?TWFyayBQ?= Wireless Networking 0 10-20-2004 07:45 PM
Adding Wireless acess point to existing network. Shawn Wireless Networking 1 10-17-2004 03:53 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57