in this scenario
foo1 ---calls---> foo2
is it possible for me to print out - when the control is within foo2 -
the caller of foo2
the information is obviously there in the stack - am wondering if by
some combination of assembly and pointer manipulation - I can print
the name of the caller of the method
Thanks for any suggestions 20 3397
"2pac" <ca******@yahoo .com> wrote in message
news:d0******** *************** ***@posting.goo gle.com... in this scenario foo1 ---calls---> foo2 is it possible for me to print out - when the control is within foo2 - the caller of foo2
the information is obviously there in the stack - am wondering if by some combination of assembly and pointer manipulation - I can print the name of the caller of the method Thanks for any suggestions
Unfortunately, the only advice that can be given to you is that
there is no standard support for such a functionality in C.
(except if foo1 explicitly receives information about the caller,
as a function parameter or in some global variable).
But yes, in platform-specific ways and in 'debug mode' compiles,
it is typically possible to obtain the information you need from
the call stack. Sometimes a dedicated API is even provided.
But you will have to ask in a forum specific to your platform
(OS, ISA & compiler)...
Regards,
-- http://www.post1.com/~ivec <> Ivan Vecerina
On 6 Sep 2003 12:46:09 -0700, in comp.lang.c , ca******@yahoo. com
(2pac) wrote: in this scenario foo1 ---calls---> foo2 is it possible for me to print out - when the control is within foo2 - the caller of foo2
Your debugger can do this, so obviously its possible. However its not
possible in standard C, you'd need to use platform specific debugging
calls. Read your compiler manual, or ask in a group specialising in
it.
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.angelfire.c om/ms3/bchambless0/welcome_to_clc. html>
2pac wrote: in this scenario foo1 ---calls---> foo2 is it possible for me to print out - when the control is within foo2 - the caller of foo2
the information is obviously there in the stack - am wondering if by some combination of assembly and pointer manipulation - I can print the name of the caller of the method Thanks for any suggestions
cat foo.c
#include <stdio.h>
int foo(const char* function, const char* file, int line) {
fprintf(stderr,
"Function foo(const char*, const char*, int)\n"
"called from function %s in file %s at line %d.\n",
function, file, line);
return 0;
}
int main(int argc, char* argv[]) {
foo(__func__, __FILE__, __LINE__);
return 0;
}
gcc -Wall -std=c99 -pedantic -o foo foo.c ./foo
Function foo(const char*, const char*, int)
called from function main in file foo.c at line 12. ca******@yahoo. com (2pac) wrote in
news:d0******** *************** ***@posting.goo gle.com on Sat 06 Sep 2003
01:46:09p: - I can print the name of the caller of the method Thanks for any suggestions
C has no methods. C has subroutines, sometimes called functions by those
who know no better. Methods are parts of object-oriented languages. Maybe
you meant to post this in an Objective-C group, maybe you just need to
learn the vocabulary better.
>in this scenario foo1 ---calls---> foo2 is it possible for me to print out - when the control is within foo2 - the caller of foo2
the information is obviously there in the stack - am wondering if by
No, it is *NOT* obvious that any function names (addresses, probably,
names, no) appear anywhere in an executable (unless placed there by
the programmer with explicit strings or using __FUNCTION__). Even
if they do, it is not obvious that they are ever loaded into memory
when run normally (that is, not under a debugger). And if the
program is run under a debugger, the debugger knows where the symbols
are, the program doesn't. The debugger also knows the file name of
the executable file, and the program doesn't (unless the programmer
hard-coded a guess in there somewhere).
The symbols aren't necessarily the name of the function, either,
especially in compilers that also support C++, where you can have
multiple functions with the same name.
Oh, yes, there is no portable way for a running program to find a
file name for its own executable file. argv[0] can be of spectacularly
little help, especially under UNIX, where argv[0] and the pathname
of the program to run are independent arguments to exec*() that
need not have any relationship to each other.
some combination of assembly and pointer manipulation - I can print the name of the caller of the method
C doesn't have methods.
Gordon L. Burdit
August Derleth wrote: C has subroutines, sometimes called functions by those who know no better.
LOL!
--
pete
"August Derleth" <li************ *****@onewest.n et> wrote in message
news:Xn******** *************** ***********@63. 223.5.101... ca******@yahoo. com (2pac) wrote in news:d0******** *************** ***@posting.goo gle.com on Sat 06 Sep 2003 01:46:09p:
- I can print the name of the caller of the method Thanks for any suggestions
C has no methods. C has subroutines, sometimes called functions by those who know no better. Methods are parts of object-oriented languages. Maybe you meant to post this in an Objective-C group, maybe you just need to learn the vocabulary better.
The standard refers to them as ``functions'' or ``function definition(s)'' .
So I don't see how you can say they are referred to as ``functions'' by
those who know no better.
"j" <ja****@bellsou th.net> wrote in message
news:ny******** *******@bignews 3.bellsouth.net ... "August Derleth" <li************ *****@onewest.n et> wrote in message news:Xn******** *************** ***********@63. 223.5.101... ca******@yahoo. com (2pac) wrote in news:d0******** *************** ***@posting.goo gle.com on Sat 06 Sep 2003 01:46:09p:
- I can print the name of the caller of the method Thanks for any suggestions C has no methods. C has subroutines, sometimes called functions by those who know no better. Methods are parts of object-oriented languages.
Maybe you meant to post this in an Objective-C group, maybe you just need to learn the vocabulary better.
The standard refers to them as ``functions'' or ``function
definition(s)'' . So I don't see how you can say they are referred to as ``functions'' by those who know no better.
I agree with you. I don't think a C programmer will call "subroutine s"
everytime when he is talking about a function.
When we are talking about "function pointer", how should we call it ?
I won't call it "subroutine s pointer" :-)
--
Jeff
"j" <ja****@bellsou th.net> wrote in
news:ny******** *******@bignews 3.bellsouth.net on Sun 07 Sep 2003
12:31:00a: "August Derleth" <li************ *****@onewest.n et> wrote in message news:Xn******** *************** ***********@63. 223.5.101... C has no methods. C has subroutines, sometimes called functions by those who know no better. Methods are parts of object-oriented languages. Maybe you meant to post this in an Objective-C group, maybe you just need to learn the vocabulary better.
The standard refers to them as ``functions'' or ``function definition(s)'' . So I don't see how you can say they are referred to as ``functions'' by those who know no better.
At base, functions are defined by the lambda calculus. This endows them
with properties C subroutines do not possess, such as a first-class status
in the programming language and the ability to be created anonymously
within another function. They are at a higher level of abstraction than
subroutines are.
The Standard apparently doesn't know better, else it would refer to
subroutines as such, or it would extend C subroutines to become functions.
It has done neither, so it apparently doesn't know any better. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: AMD |
last post by:
Hi,
I need to write a Win32 DLL and I would like to use Python instead of
VB, C++ or Delphi. Is this possible?
Thank you,
Andre M. Descombes
|
by: John Smith |
last post by:
Hi,
I'm writing a library in C++ which is supposed to be used by people using C.
One function I have must return a string to users which is arbitrary length.
The user must be able to use this string as "char *" so I was wondering if
the following construct is safe:
char *Func()
{
static string str;
|
by: Santi |
last post by:
Hi,
Is there anyway to find if a dll or exe has been compiled from C++ or Delphi
or whatever language?
|
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?
|
by: Terentius Neo |
last post by:
Is it possible to combine (in DB2 UDB 8.1) a stored procedure and a
select statement? I mean something like this:
Select
c.number,
call procedure( c.number ) as list
from
table c
With best regards
| |
by: eSolTec, Inc. 501(c)(3) |
last post by:
Thank you in advance for any and all assistance, it is GREATLY appreciated.
I'm wondering if there is a way to duplicate a function in regedit of find
and find next for keywords programmatically, then to list them in a treeview
or listbox?
If so, could someone point me to some code?
--
Michael Bragg, President
eSolTec, Inc.
a 501(C)(3) organization
|
by: pamelafluente |
last post by:
Hi guys,
How do I get the full name of the current (overload) function or sub
(whatever it be) ?
Sub SomeFunction()
Dim FullNameOfThisFunction = ???
msgbox(FullNameOfThisFunction )
|
by: kj7ny |
last post by:
Is there a way that I can programmatically find the name of a method I
have created from within that method? I would like to be able to log
a message from within that method (def) and I would like to include
the name of the method from which it was written without having to
hard-code that value in every message string. While we're at it, is
there a way to programmatically get the name of the class and the
module while I'm at it?
...
|
by: Simon |
last post by:
I heard that we could do that by using AJAX. Could anybody share how to do
it? Thanks.
|
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,...
|
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...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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
| |