Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Stack Pointer..?

Reply
Thread Tools

Stack Pointer..?

 
 
7trackers@gmail.com
Guest
Posts: n/a
 
      10-10-2005
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...?

 
Reply With Quote
 
 
 
 
Walter Roberson
Guest
Posts: n/a
 
      10-10-2005
In article <(E-Mail Removed). com>,
<(E-Mail Removed)> wrote:
: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 can't do your homework in portable C.
--
"It is important to remember that when it comes to law, computers
never make copies, only human beings make copies. Computers are given
commands, not permission. Only people can be given permission."
-- Brad Templeton
 
Reply With Quote
 
 
 
 
pemo
Guest
Posts: n/a
 
      10-10-2005

<(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...
> 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.


 
Reply With Quote
 
mario.demiguel@gmail.com
Guest
Posts: n/a
 
      10-10-2005

http://www.velocityreviews.com/forums/(E-Mail 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...?


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.

 
Reply With Quote
 
C Wegrzyn
Guest
Posts: n/a
 
      10-10-2005
(E-Mail Removed) wrote:

>(E-Mail 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...?
>>
>>

>
>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.

 
Reply With Quote
 
Malcolm Dew-Jones
Guest
Posts: n/a
 
      10-10-2005
(E-Mail 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.



--

This programmer available for rent.
 
Reply With Quote
 
Jack Klein
Guest
Posts: n/a
 
      10-11-2005
On 10 Oct 2005 11:48:02 -0700, (E-Mail Removed) wrote in
comp.lang.c:

>
> (E-Mail 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...?

>
> 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.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
 
Reply With Quote
 
Ben Pfaff
Guest
Posts: n/a
 
      10-11-2005
(E-Mail Removed) writes:

> 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.
--
"Am I missing something?"
--Dan Pop
 
Reply With Quote
 
Dave Thompson
Guest
Posts: n/a
 
      10-17-2005
On 10 Oct 2005 13:28:52 -0700, (E-Mail Removed) (Malcolm
Dew-Jones) wrote:

> (E-Mail 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

<snip: added 'from' parameter to every function and call>
> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why does std::stack::pop() not throw an exception if the stack is empty? Debajit Adhikary C++ 36 02-10-2011 08:54 PM
C/C++ compilers have one stack for local variables and return addresses and then another stack for array allocations on the stack. Casey Hawthorne C Programming 3 11-01-2009 08:23 PM
stack frame size on linux/solaris of a running application stack Surinder Singh C Programming 1 12-20-2007 01:16 PM
Why stack overflow with such a small stack? Kenneth McDonald Ruby 7 09-01-2007 04:21 AM
"stack level too deep"... because Threads keep their "starting" stack Sam Roberts Ruby 1 02-11-2005 04:25 AM



Advertisments