Stack Pointer..?

7

7trackers

Hi people...

Here's my question...

a function other than main is getting executed
you have to find out which function called this function

how can we do in C...?
 
W

Walter Roberson

:a function other than main is getting executed
:you have to find out which function called this function

:how can we do in C...?

You can't do your homework in portable C.
 
P

pemo

Hi people...

Here's my question...

a function other than main is getting executed
you have to find out which function called this function

how can we do in C...?

Use a debugger and breakpoints? Or is this an academic question.
 
M

mario.demiguel

Hi people...

Here's my question...

a function other than main is getting executed
you have to find out which function called this function

how can we do in C...?

I believe using __FUNCTION__ will show the current function's name, I'm
not sure about showing the calling function's name. My best advice,
try searching the groups for __FUNCTION__ to see if this question, or a
similar one, has already been answered.
 
C

C Wegrzyn

(e-mail address removed) wrote:



I believe using __FUNCTION__ will show the current function's name, I'm
not sure about showing the calling function's name. My best advice,
try searching the groups for __FUNCTION__ to see if this question, or a
similar one, has already been answered.
Are you using gcc? If so you can get access to the frames, which will
help you figure out how you got to where you are.
 
M

Malcolm Dew-Jones

(e-mail address removed) wrote:
: Hi people...

: Here's my question...

: a function other than main is getting executed
: you have to find out which function called this function

: how can we do in C...?

You could rewrite your functions to include that information

(No pretense of being real code)

main()
{
do_something("from main",1,2,3);
}

do_something( char *from, int i, int j, int k)
{
do_something_else("do_something",'a','b','c');
}

do_something_else( char *from, etc...)
{
printf("I was called from %s",from);
}


To get a full stack trace you would have to add some kind of link as well,
but I haven't thought to add that here.

Various compilers and debuggers have options to help do this sort of thing
much easier.
 
J

Jack Klein

I believe using __FUNCTION__ will show the current function's name, I'm
not sure about showing the calling function's name. My best advice,
try searching the groups for __FUNCTION__ to see if this question, or a
similar one, has already been answered.

Unfortunately, this isn't anything in the standard C language.
 
B

Ben Pfaff

a function other than main is getting executed
you have to find out which function called this function

If there's a specific function that wants to know this, then you
might be able to rig something up with a macro, e.g.
#define function(arg1, arg2) real_function(arg1, arg2, __func__)

...

void real_function(int arg1, void *arg2, const char *calling_function)
{
...
}
There is no portable, general solution.
 
D

Dave Thompson

(e-mail address removed) wrote:
: Hi people...

: Here's my question...

: a function other than main is getting executed
: you have to find out which function called this function

: how can we do in C...?

You could rewrite your functions to include that information
To get a full stack trace you would have to add some kind of link as well,
but I haven't thought to add that here.

Various compilers and debuggers have options to help do this sort of thing
much easier.

To be clear: compilers and debuggers (usually) have options to trace
back the calling stack or equivalent. None that I know of do this by
the mechanism of adding a special from_name parameter.
- David.Thompson1 at worldnet.att.net
 

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
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top