all tasks
This commit is contained in:
parent
b83f433714
commit
68f8f3e56b
14735 changed files with 178959 additions and 0 deletions
39
Task/Stack-traces/C/stack-traces-1.c
Normal file
39
Task/Stack-traces/C/stack-traces-1.c
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <execinfo.h>
|
||||
|
||||
#define MAX_BT 200
|
||||
|
||||
void print_stack_trace()
|
||||
{
|
||||
void *buffer[MAX_BT];
|
||||
int n;
|
||||
|
||||
n = backtrace(buffer, MAX_BT);
|
||||
fprintf(stderr, "--- (depth %d) ---\n", n);
|
||||
backtrace_symbols_fd(buffer, n, STDERR_FILENO);
|
||||
}
|
||||
|
||||
|
||||
void inner(int k)
|
||||
{
|
||||
print_stack_trace();
|
||||
}
|
||||
|
||||
void middle(int x, int y)
|
||||
{
|
||||
inner(x*y);
|
||||
}
|
||||
|
||||
void outer(int a, int b, int c)
|
||||
{
|
||||
middle(a+b, b+c);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
outer(2,3,5);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue