Calling a funciton implicitly ?

I

iceColdFire

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+
 
J

John Carson

iceColdFire said:
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?
 
I

iceColdFire

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
 
J

John Carson

iceColdFire said:
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.
 
K

Kai-Uwe Bux

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
 
N

Niels Dybdahl

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
 
I

iceColdFire

::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
 
M

msalters

iceColdFire said:
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::eek:perator->() first.

HTH,
Michiel Salters
 

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

No members online now.

Forum statistics

Threads
474,202
Messages
2,571,057
Members
47,668
Latest member
SamiraShac

Latest Threads

Top