Stack Pointer..?

Discussion in 'C Programming' started by 7trackers@gmail.com, Oct 10, 2005.

  1. Guest

    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...?
    , Oct 10, 2005
    #1
    1. Advertising

  2. In article <>,
    <> 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
    Walter Roberson, Oct 10, 2005
    #2
    1. Advertising

  3. pemo Guest

    <> wrote in message
    news:...
    > 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.
    pemo, Oct 10, 2005
    #3
  4. Guest

    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.
    , Oct 10, 2005
    #4
  5. C Wegrzyn Guest

    wrote:

    > 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.
    C Wegrzyn, Oct 10, 2005
    #5
  6. 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.
    Malcolm Dew-Jones, Oct 10, 2005
    #6
  7. Jack Klein Guest

    On 10 Oct 2005 11:48:02 -0700, wrote in
    comp.lang.c:

    >
    > 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/~ajo/docs/FAQ-acllc.html
    Jack Klein, Oct 11, 2005
    #7
  8. Ben Pfaff Guest

    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
    Ben Pfaff, Oct 11, 2005
    #8
  9. On 10 Oct 2005 13:28:52 -0700, (Malcolm
    Dew-Jones) wrote:

    > 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
    Dave Thompson, Oct 17, 2005
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. anonymous
    Replies:
    3
    Views:
    384
    S.Tobias
    Jan 13, 2005
  2. anonymous
    Replies:
    4
    Views:
    734
    S.Tobias
    Jan 28, 2005
  3. code break

    stack pointer and frame pointer

    code break, Oct 18, 2006, in forum: C Programming
    Replies:
    4
    Views:
    550
    Walter Roberson
    Oct 18, 2006
  4. Surinder Singh
    Replies:
    1
    Views:
    1,175
    Richard Bos
    Dec 20, 2007
  5. Casey Hawthorne
    Replies:
    3
    Views:
    1,064
    Flash Gordon
    Nov 1, 2009
Loading...

Share This Page