473,804 Members | 2,122 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

to identify the caller of a function



Hi Everyone,

I have a function utility() which is a part of a library and i would
like to know as to who is
invoking the function. I could request that information as a parameter
enumeration, but i would like to know if there is any other smart way
of doing the same?

Thanks in advance!!!
Jan 9 '08 #1
7 4319
Rahul wrote:
>

Hi Everyone,

I have a function utility() which is a part of a library and i would
like to know as to who is
invoking the function. I could request that information as a parameter
enumeration, but i would like to know if there is any other smart way
of doing the same?
My way of doing that involves using macros and a non standard predefined
macro (but that exists on many current compilers and even if it didn't you
can easily detect that and provide some dummy version) so it might not be
that smart. But it works nicely, like this:

// this is your real function (that will receive as "caller" the callee)
void func_real(type1 arg1, type2 arg2, char const* caller);
#define func(arg1, arg2) func_real((arg1 ), (arg2), __FUNCTION__)

Notice the usage of __FUNCTION__. The idea is when you "call" func you just
expand the macro, expanding to "func_real((arg 1), (arg2), __FUNCTION__)"
and __FUNCTION__ (the non standard predefined macro I mentioned) will be
filled by the preprocessor with the current function name so you get that
to your actual function.

If someone has better options that still make it possible to use normal
function call "func(arg1, arg2)" syntax without macros please advise...

--
Dizzy

Jan 9 '08 #2
Rahul wrote:
>
I have a function utility() which is a part of a library
and i would like to know as to who is invoking the function.
I could request that information as a parameter enumeration,
but i would like to know if there is any other smart way
of doing the same?
What do you want to do with the information about caller?
If(caller is ok)...?

If you want to change behaviour of called function depended from
caller, then there is other legal ways to do it, for example, to make
for caller a class with a member, which will do correct things for the
caller.

Maksim A. Polyanin
old page about some C++ improvements:
http://grizlyk1.narod.ru/cpp_new
Jan 9 '08 #3
On Jan 9, 6:48 pm, Grizlyk <grizl...@yande x.ruwrote:
Rahul wrote:
I have a function utility() which is a part of a library
and i would like to know as to who is invoking the function.
I could request that information as a parameter enumeration,
but i would like to know if there is any other smart way
of doing the same?

What do you want to do with the information about caller?
If(caller is ok)...?

If you want to change behaviour of called function depended from
caller, then there is other legal ways to do it, for example, to make
for caller a class with a member, which will do correct things for the
caller.

Maksim A. Polyanin
old page about some C++ improvements:http://grizlyk1.narod.ru/cpp_new
well, the logic of utility depends on the caller, and moreover utility
wouldn't like to service unknown callers ( as in callers should
register before hand )...
Jan 9 '08 #4
Rahul wrote:
On Jan 9, 6:48 pm, Grizlyk <grizl...@yande x.ruwrote:
>Rahul wrote:
>>I have a function utility() which is a part of a library
and i would like to know as to who is invoking the function.
I could request that information as a parameter enumeration,
but i would like to know if there is any other smart way
of doing the same?

What do you want to do with the information about caller?
If(caller is ok)...?

If you want to change behaviour of called function depended from
caller, then there is other legal ways to do it, for example, to make
for caller a class with a member, which will do correct things for
the caller.

Maksim A. Polyanin
old page about some C++ improvements:http://grizlyk1.narod.ru/cpp_new

well, the logic of utility depends on the caller, and moreover utility
wouldn't like to service unknown callers ( as in callers should
register before hand )...
If the callers register, they should be given unique IDs, so you just
make 'utility()' request the ID from the caller (as one of its args).

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jan 9 '08 #5
On Jan 9, 5:54*pm, Rahul <sam_...@yahoo. co.inwrote:
>
well, the logic of utility depends on the caller, and moreover utility
wouldn't like to service unknown callers ( as in callers should
register before hand )...- Hide quoted text -
The words "design error" are flashing in big red letters in
my brain ... it doesn't make sense to disqualify callers
who have linked to your library, that's the sort of security
you'd impose on a distributed service, not a function call.

If you still want to impose something like this, then just
have:

typedef <something hereUtilityUseH andle;

// callers must get a handle first ...
// (function concocts a verifyable handle and returns it)
UtilityUseHandl e register(<some credentials>);

// utility function - must pass valid handle else
// it'll throw an InvalidUtilityU seHandle exception
<retvaluse_util ity_fn(
const UtilityUseHandl e& valid_registere d_handle,
<other parameters>
) /* throw (InvalidUtility UseHandle) */ ;

// finished, thank you ...
void unregister(
const UtilityUseHandl e& valid_registere d_handle
) /* throw (InvalidUtility UseHandle) */ ;

Jan 9 '08 #6
dizzy wrote:
>
void func_real(type1 arg1, type2 arg2, char const* caller);
#define func(arg1, arg2) func_real((arg1 ), (arg2), __FUNCTION__)

__FUNCTION__ will be filled by the preprocessor with the
current function name so you get that to your actual function.

If someone has better options that still make it possible
to use normal function call "func(arg1, arg2)" syntax
without macros please advise...
And what will be?

***
typedef int type1;
typedef int type2;

//
typedef
void
(*t_func)
(type1 arg1, type2 arg2);

typedef
void
(*t_func_real)
(type1 arg1, type2 arg2, t_func func);

//
template<t_func _real Fn>
class Tcaller
{
public:

static
void
call(type1 arg1, type2 arg2)
{
Fn(arg1, arg2, call);
}
};

//usage
void func_real(type1 arg1, type2 arg2, t_func func);

void
foo(type1 arg1, type2 arg2)
{
Tcaller<func_re al>::call(arg1, arg2);
}

***

Is it better? I am not sure.

Maksim A. Polyanin
old page about some C++ improvements:
http://grizlyk1.narod.ru/cpp_new
Jan 9 '08 #7
Rahul wrote:
>
well, the logic of utility depends on the caller, and
moreover utility wouldn't like to service unknown callers
( as in callers should register before hand )...
What the purpose of the registration and what means "unknown"? What
kind of information of caller are expected by service?

Do you want to trace usage of the service (called)? There is
development stuffs as profiler.

If you need portable real-time tracing as normal execution of service,
that access to the service can be done, for example, as interface like
open-write-close.

Maksim A. Polyanin
old page about some C++ improvements:
http://grizlyk1.narod.ru/cpp_new
Jan 9 '08 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1913
by: Mark | last post by:
The situtation is that I'm trying to ensure that certain functions are only called by functions that I want them to be called from. I have a popup window which has a function which calls a function in the opener window (this works fine). The only thing is when I go to get the caller property of the function in the opener window it is null, it does not return the function in the popup window that called it. Any ideas?
9
4374
by: jaden10001 | last post by:
I have read that the function.caller method is now depricated. I see alot of browsers still support it but Opera 7 does not. Is there a way to get the name of the caller of a function in Opera 7?
4
3653
by: Thomas Mlynarczyk | last post by:
Hi, I stumbled over a strange behaviour of Mozilla. When I want to access the caller property of a function that was not called from within another function, Mozilla seems to abort the script. No error message, no hang, just stopping script execution at that point. Why? And what is the remedy? Greetings, Thomas
8
6626
by: Rakehs | last post by:
Hi, I have a method Show() which is invoked by several methods at different intervals. I want to identify the calling method within Show() whenever it is invoked. How do i do this? Thanks in advance Rakesh
14
1877
by: Genival | last post by:
Hello all... First sorry my bad English. Look next code Dim oDS as Dataset ' <= Caller oDs = MyFunc 'other caller type Dim i as integer = MyFunc
9
16849
by: Csaba Gabor | last post by:
Inside a function, I'd like to know the call stack. By this I mean that I'd like to know the function that called this one, that one's caller and so on. So I thought to do: <script type='text/javascript'> function myFunc(lev) { // if (lev) return myFunc(lev-1); var aStack=; nextFunc = arguments.callee;
8
10510
by: all.junks | last post by:
Hi, Let's say I'm in function foo. I am trying to find the function(or return address) which called foo. Initially, I thought I could use stack base pointer(ebp+4) to find the return address. However, my compiler(vs7) would go through so many function call and ebp+4 points to somewhere in kernel32.
8
1553
by: contactmayankjain | last post by:
Hi, Can you tell me is there some procedure to calculate the number of calls of a function during run time? How to insert a counter and how to increment it? and possibly which function have called it how many times?
7
4433
by: =?UTF-8?B?QW50w7NuaW8gTWFycXVlcw==?= | last post by:
Hi, Sorry if this's been discussed before, I couldn't find it. As well you know, the ECMAScript standard doesn't include any way to access a function's caller. This has been available on Mozilla and IE as a 'caller' property of function objects, and it seems Konqueror/Safari now have it too. Opera doesn't. And what bothers me is that it is marked as 'deprecated'. I've seen people I respect swear by their lives that it is *good* to
0
9716
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9595
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10604
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10101
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7643
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6870
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5536
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4314
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3005
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.