C程序发现堆栈增长的方向 [英] C program to find direction of stack growth
本文介绍了C程序发现堆栈增长的方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要如何找到在C堆栈是否正取得进展正向或反向?将这项工作?
INT J = 0;
INT K = 0;如果(安培; K>&安培; j)条
的printf(堆栈中的前进方向);否则,如果(安培; K<&安培; j)条
的printf(堆栈是反向增长的);
解决方案
要可靠,一个人必须要找到两个函数调用之间的区别。
无效FUNC(INT * P){
INT I;
如果(!P)
FUNC(安培; I)
否则如果(P&所述;&放大器;ⅰ)
的printf(堆栈向上生长\\ n);
其他
的printf(堆栈向下增长\\ n);
}FUNC(NULL);
请注意,这不会给你一个答案的 C 的,而是关于你的编译器。
How do I find in C whether a stack is progressing in forward or reverse direction ? WIll this work?
int j = 0;
int k = 0;
if (&k > &j)
printf ("Stack is growing in forward direction");
else if (&k < &j)
printf ("Stack is growing in reverse direction");
解决方案
To be reliable, one would have to find the difference between two function calls.
void func(int *p) {
int i;
if (!p)
func(&i);
else if (p < &i)
printf("Stack grows upward\n");
else
printf("Stack grows downward\n");
}
func(NULL);
Note that this won't give you an answer about C, but about your compiler.
这篇关于C程序发现堆栈增长的方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文