关于堆栈的疑问 [英] doubt on regarding stacks

查看:57
本文介绍了关于堆栈的疑问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

如果这是一个愚蠢的问题,请不要向我开火

有没有办法知道堆栈增长的方向

pmm

解决方案

" pmm" <亩************ @ hotmail.com>写道:

有没有办法知道哪个方向堆栈增长




不在ISO C中。事实上,ISO C不保证你甚至__ve_

堆栈,因为你理解这个词。


Richard


< blockquote>

" Richard Bos" < rl*@hoekstra-uitgeverij.nl>在消息中写道

news:42 *************** @ news.individual.net ...

" pmm" <亩************ @ hotmail.com>写道:

有没有办法知道哪个方向堆栈增长



不在ISO C中。事实上,ISO C并不保证当你理解那个词时,你甚至_have_
堆栈。




当然正确但是OTOH,你会有一个非常不寻常的平台,如果

你没有。


你可以使用的一个肮脏的伎俩(所有警告都设置为

非便携性和合规性)是

取一些局部变量的地址,调用一个函数来分配另一个

local并取得该地址。然后对地址

的简单比较会产生堆栈增长的方向(假设你的编译器确实有一个堆栈并使用它)。


然而,这属于肮脏的诡计。部门和你没有

保证它确实可以在您的目标平台上运行。


通常查阅CPU /编译器上的文档会产生更多

可靠答案。




蒲公英写道:

" Richard Bos" < rl*@hoekstra-uitgeverij.nl>在消息中写道
新闻:42 *************** @ news.individual.net ...

" pmm" <亩************ @ hotmail.com>写道:

有没有办法知道堆栈的增长方向
不是在ISO C中。事实上,ISO C并不能保证你甚至
_have_你明白这个词的堆栈。



正确的,当然,但是OTOH,你会有一个非常不寻常的



平台如果你做了不是。

你可以使用的一个肮脏的技巧(所有警告设置为不可移植性和合规性)是取一些局部变量的地址,调用函数分配
另一个本地人也拿这个地址。然后对
地址的简单比较将产生堆栈增长的方向(假设你的
编译器确实有一个堆栈并使用它)。

但是,这会下降进入肮脏的诡计部门和你没有
保证它确实可以在你的目标
平台上工作。
通常查阅你的CPU /编译器上的文档将产生
更可靠的答案。




感谢您的回复

我确实做了上述伎俩,但我觉得这是一种不好的做法。我想

有一个更好的代码所以我发布到这个组。


请告诉我正确的概念。请推荐任何网页

处理上述概念

非常感谢


Hi all,
Plz dont fire at me if this is a silly question
Is there any way to know in which direction stack grows
pmm

解决方案

"pmm" <mu************@hotmail.com> wrote:

Is there any way to know in which direction stack grows



Not in ISO C. In fact, ISO C does not guarantee that you even _have_ a
stack as you understand that term.

Richard



"Richard Bos" <rl*@hoekstra-uitgeverij.nl> wrote in message
news:42***************@news.individual.net...

"pmm" <mu************@hotmail.com> wrote:

Is there any way to know in which direction stack grows



Not in ISO C. In fact, ISO C does not guarantee that you even _have_ a
stack as you understand that term.



Correct, of course, but OTOH, you would have a pretty unusual platform if
you did not.

One filthy trick you could employ (with all warnings set abut
non-portability and compliance) is to
take the address of some local variable, call a function allocating another
local and take that address,too. Then a simple comparison of the addresses
would yield the direction in which the stack grows (assuming your compiler
does indeed have a stack and uses it).

However, that falls into the "Filthy Tricks" department and you no
guarantees whatsoever that it will indeed work on your target platform.

Usually consulting the documentation on your CPU/Compiler will yield more
reliable answers.



dandelion wrote:

"Richard Bos" <rl*@hoekstra-uitgeverij.nl> wrote in message
news:42***************@news.individual.net...

"pmm" <mu************@hotmail.com> wrote:

Is there any way to know in which direction stack grows
Not in ISO C. In fact, ISO C does not guarantee that you even _have_ a stack as you understand that term.



Correct, of course, but OTOH, you would have a pretty unusual


platform if you did not.

One filthy trick you could employ (with all warnings set abut
non-portability and compliance) is to
take the address of some local variable, call a function allocating another local and take that address,too. Then a simple comparison of the addresses would yield the direction in which the stack grows (assuming your compiler does indeed have a stack and uses it).

However, that falls into the "Filthy Tricks" department and you no
guarantees whatsoever that it will indeed work on your target platform.
Usually consulting the documentation on your CPU/Compiler will yield more reliable answers.



Thanks for the reply
I sure did the above trick but I felt like a bad practice. I thought of
to have a better code so I posted into this group.

plz let me know the correct concepts. please recommend any web pages
deals with the above concepts
thanks a lot


这篇关于关于堆栈的疑问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆