how to get function call stack

This is a discussion on how to get function call stack within the C Programming forums, part of the General Programming Boards category; George2, perhaps you'd like to combine replies to several people in a single post Any decent debugger will do. If ...

  1. #16
    Registered User
    Join Date
    Mar 2006
    Posts
    725
    George2, perhaps you'd like to combine replies to several people in a single post

    Any decent debugger will do. If you use MSVC, the built-in debugger could be used; if you use gcc then try gdb. There are also high-end commercial debuggers avaliable. A quick read of the debugger's documentation should give you a basic idea of how to use it for your program.
    Code:
    #include <stdio.h>
    
    void J(char*a){int f,i=0,c='1';for(;a[i]!='0';++i)if(i==81){
    puts(a);return;}for(;c<='9';++c){for(f=0;f<9;++f)if(a[i-i%27+i%9
    /3*3+f/3*9+f%3]==c||a[i%9+f*9]==c||a[i-i%9+f]==c)goto e;a[i]=c;J(a);a[i]
    ='0';e:;}}int main(int c,char**v){int t=0;if(c>1){for(;v[1][
    t];++t);if(t==81){J(v[1]);return 0;}}puts("sudoku [0-9]{81}");return 1;}

  2. #17
    Registered User
    Join Date
    Sep 2003
    Posts
    224
    Quote Originally Posted by George2
    Hi Yasir_Malik,




    I want to know which function calls current function in some certain situations. For example, when function a calls functions b, and function b calls function c, in function c, I want to get the information like, a-->b-->c.

    Any ideas?


    regards,
    George
    Perhaps for each function you call you could save the function name and arguments inside a global linked list, and then whenever you need to, print out out the contents of the linked list. Each time you exit a function, you can remove the last element of the linked list. A stack would work for this, but I think you want to traverse the structure without removing elements.

  3. #18
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    Google cache: http://64.233.187.104/search?q=cache...s&ct=clnk&cd=2

    I don't know man. Here's a bunch of bibliographic information about the article.

    Code:
    @Article{Pescio:1997:STA,
      author =       "Carlo Pescio",
      title =        "Stack Trace Assertions Using {COFF}",
      journal =      j-CCCUJ,
      volume =       "15",
      number =       "6",
      pages =        "41--??",
      month =        jun,
      year =         "1997",
      CODEN =        "CCUJEX",
      ISSN =         "1075-2838",
      bibdate =      "Fri May 16 08:01:41 1997",
      bibsource =    "http://www.cuj.com/1506toc.htm",
      acknowledgement = ack-nhfb,
    }

    ╔╗╔╦══╦╗╔╦══╦╗
    ║╚╝║╔╗║╚╝║╔╗║║
    ║╔╗║╠╣║╔╗║╠╣╠╣
    ╚╝╚╩╝╚╩╝╚╩╝╚╩╝

    codez http://code.google.com/p/zxcvbn/

  4. #19
    Registered User
    Join Date
    Mar 2006
    Posts
    725
    Perhaps for each function you call you could save the function name and arguments inside a global linked list
    Woah, easy there. A stack in terms of a dynamic array would do just fine, and be faster to boot. Better cache, less space, fewer instructions (push = increment counter + assign, pop = decrement counter).
    Code:
    #include <stdio.h>
    
    void J(char*a){int f,i=0,c='1';for(;a[i]!='0';++i)if(i==81){
    puts(a);return;}for(;c<='9';++c){for(f=0;f<9;++f)if(a[i-i%27+i%9
    /3*3+f/3*9+f%3]==c||a[i%9+f*9]==c||a[i-i%9+f]==c)goto e;a[i]=c;J(a);a[i]
    ='0';e:;}}int main(int c,char**v){int t=0;if(c>1){for(;v[1][
    t];++t);if(t==81){J(v[1]);return 0;}}puts("sudoku [0-9]{81}");return 1;}

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Confused about Memory
    By gL_nEwB in forum C++ Programming
    Replies: 22
    Last Post: 06-20-2006, 08:32 PM
  2. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  3. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-30-2005, 12:21 AM
  4. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 02:27 PM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 06:06 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21