判断栈的增长
其實(shí)就是在函數(shù)中記錄自動變量的地址; 遞歸再次調(diào)用函數(shù)重復(fù)入棧再次記錄其地址, 比較兩次地址, 就可以知道棧幀增長的方向,自然就知道了棧增長的方向
?
#include<stdio.h> static void find_stack_direction(void); static int stack_dir; int main(void) {find_stack_direction();if(stack_dir==1)puts("stack grew upward");elseputs("stack grew downward");return 0; } static void find_stack_direction (void) {static char *addr = NULL; /* address of first`dummy', once known */auto char dummy; /* to get stack address */if (addr == NULL){ /* initial entry */addr = &dummy;find_stack_direction (); /* recurse once */}else /* second entry */if (&dummy > addr)stack_dir = 1; /* stack grew upward */elsestack_dir = -1; /* stack grew downward */ }
?
總結(jié)
- 上一篇: fastdfs
- 下一篇: Lucene下载及测试