问题描述
在此面试问题迷迷糊糊的地方,
Stumbled upon this interview question somewhere,
在C,
给定一个变量 X
,你怎么找出是否该变量的空间在堆栈或堆上分配的?
In C,Given a variable x
, how do you find out if the space for that variable is allocated on the stack or heap?
(有没有办法找到它编程,而不是不必通过符号表等?而且,如果空间在堆栈中分配或堆有什么实际意义并找到?)
(Is there any way to find it out programatically and not having to go through the symbol table, etc? And does finding if the space is allocated in stack or heap has any practical implications?)
推荐答案
否,不是一般的。
你知道GCC 的?
Do you know of gcc -fsplit-stack
?
它是由执行决定是否分配一个连续的叠层或者块被交错与存储器堆块的堆叠。祝你好运搞清楚块是分配给堆或当后者拆分堆栈。
It is up to the implementation to decide whether to allocate a contiguous stack or a stack where blocks are interleaved with heap blocks in memory. Good luck figuring out whether a block was allocated for the heap or the stack when the latter is split.
的注:这是相当无用的信息反正... 的
这篇关于如何找到一个变量在堆栈或堆中分配的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!