By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,851 Members | 1,001 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,851 IT Pros & Developers. It's quick & easy.

Calling a funciton implicitly ?

P: n/a
Hi,

Is there some way where I can call a function without explicitly making
a function call...

I need this in a scenario where a function is called say f(); and it
automatically calls some logging functions, logA(),logB() etc...
however these calls dont exist in f() body {}...

Thanks,
:-)
+aacpp+

Jul 23 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
"iceColdFire" <ic*******@yahoo.com> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com
Hi,

Is there some way where I can call a function without explicitly
making a function call...

I need this in a scenario where a function is called say f(); and it
automatically calls some logging functions, logA(),logB() etc...
however these calls dont exist in f() body {}...


What are you trying to accomplish? Why can't the function calls be in the
body of f()? Since there has to be some way to indicate that the function is
to be called, what way of indicating it would you find acceptable?

--
John Carson

Jul 23 '05 #2

P: n/a
Hi John.,
Indeed your interpretation is ture...

But somehow I am ttrying to use function calls inside other functions
such that the call code is not visible to the programmer...

some way should exist...is there any way to know that a particular
function has been called without using explicit flags or
vriables...Maybe this logic works..

thanks,
a.a.cpp

Jul 23 '05 #3

P: n/a
"iceColdFire" <ic*******@yahoo.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com
Hi John.,
Indeed your interpretation is ture...
I didn't give an interpretation, I asked questions. I didn't get a lot of
answers.
But somehow I am ttrying to use function calls inside other functions
such that the call code is not visible to the programmer...
If you are talking about doing this in a program's source code, then it
might be possible with some sort of macro trickery but that would depend on
the specific details. Macro trickery is fairly commonly used in order to log
dynamic memory allocation and deletion. If you want to affect a running
program, then that is platform specific (and could be either easy or very
hard depending on the details).
some way should exist...is there any way to know that a particular
function has been called without using explicit flags or
vriables...Maybe this logic works..


The Windows operating system provides built-in support for what is called
"sub-classing". Each window type (misleadingly called "class") has
associated with it a "window procedure" for processing messages to the
window. You can however replace this window procedure with a function of
your own and, within your own function, call the original function. This
makes it possible to in effect add processing (logging, for example) to the
original function without the function's knowledge. Windows also has built
in support for what are called "hooks" which allow for the monitoring of
messages and other stuff. You can execute your own functions conditional on
what is intercepted. For working with Windows functions more generally,
there are other more advanced techniques. I have never used it, but the
Detours library is useful for some of this stuff.

http://research.microsoft.com/sn/detours/

In any event, to get further guidance, you will need to be very specific
about what you want to accomplish and, unless you are after an internal
source code solution, ask in newsgroups dedicated to the platforms of
interest.

--
John Carson

Jul 23 '05 #4

P: n/a
> But somehow I am ttrying to use function calls inside other functions
such that the call code is not visible to the programmer...

some way should exist...is there any way to know that a particular
function has been called without using explicit flags or
vriables...Maybe this logic works..


It sounds a little bit like what BoundsChecker does. It does
"instrumentation" of the code, where it insert calls to boundary and
stack-checking functions during compile time. So it is possible, but it is
definitely not easy.

A different approach is to write your own preprocessor.

Niels Dybdahl
Jul 23 '05 #5

P: n/a
iceColdFire wrote:

[snip]
But somehow I am ttrying to use function calls inside other functions
such that the call code is not visible to the programmer...

some way should exist...


No, it *should not*: in any language, what happens should be visible to the
programmer. Otherwise, programming would be impossible. The way it works
and the way it should work in programming is: what you get is what you
write. Compilers are not in the business of reading minds. In particular, a
function should not be called by magic white space in your code.
Best

Kai-Uwe Bux
Jul 23 '05 #6

P: n/a
::thanks Niels,John and Kai...

I am looking upto Niels answer...however I dont know how bounds checker
works and how do I do 'instrumenting' of code....

+::Niels--Links requested...

Thanks all,
a.a.cpp

Jul 23 '05 #7

P: n/a

iceColdFire wrote:
Hi,

Is there some way where I can call a function without explicitly making a function call...

I need this in a scenario where a function is called say f(); and it
automatically calls some logging functions, logA(),logB() etc...
however these calls dont exist in f() body {}...


Such a thing is commonly called Aspect Oriented Programming.
It's not in C++. There are some tricks to fake it, though. E.g.
ptr->f() looks like a call to myClass::f(), but in fact it calls
myClass* mySmartPtr::operator->() first.

HTH,
Michiel Salters

Jul 23 '05 #8

P: n/a
"iceColdFire" <ic*******@yahoo.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com
thanks Niels,John and Kai...


I am looking upto Niels answer...however I dont know how bounds
checker works and how do I do 'instrumenting' of code....


http://www.microquill.com/heapagent/ha_comp.htm

--
John Carson
Jul 23 '05 #9

P: n/a

"iceColdFire" <ic*******@yahoo.com> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
Hi,

Is there some way where I can call a function without explicitly making
a function call...

I need this in a scenario where a function is called say f(); and it
automatically calls some logging functions, logA(),logB() etc...
however these calls dont exist in f() body {}...


Sounds like:

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

Jeff Flinn
Jul 23 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.