由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - function pointer 是compile time还是run time得到地址的?
相关主题
一道面试题Leetcode Copy List with Random Pointer Runtime Error?
stack grows upward or downward问leetcode上surrounded regions,新的test case出runtime error
请问Intel phone interview都会问那方便的问题?刚才电面,HM居然问我recruiter是怎么找到我的
请教一个问题,发两个包子。刚一遍最对NQueens,发个贴以自鼓励。
heap&stack Linux vs. Windows  (转载)Is leetcode OJ down?
F家电面又要做题了,郁闷
implement 3 stack in an array问一道刚面试完的algorithm 的题, 面试官非要最优解,我想不出来啊
LeetCode Jump Game [Runtime Error]给大家看几道C 小程序
相关话题的讨论汇总
话题: function话题: pointer话题: stack话题: compile话题: time
进入JobHunting版参与讨论
1 (共1页)
n*******t
发帖数: 6
1
for example:
我有两个function pointer, 分别指向两个不同function。
complie的时候,这两个function pointer就得到function地址了吗?
可以用两个function pointer之差来indicate 系统stack 是upward 还是downward吗?
FLAG的一个面试官说不可以,因为function pointer是compile time 得到地址的。
stack 是runtime形成的。
然后把我往网上上的一个很popular的解法上引导。
但是网上所有关于这个解法的讨论都说,是因为compiler 优化造成compile time 的地
址和stack 无关。 这样,不是把gcc 的优化去掉,或者标成volatile不就可以了吗?
再问一个base class 和 相应 derived class的memory layout 能说明stack grow
direction 吗?
面试官也说不行。说,就是扯上virtual inheritance, 也是compile stage的。
s****a
发帖数: 794
2
runtime的吧
n*******t
发帖数: 6
3
可以用两个function pointer之差来indicate 系统stack 是upward 还是downward吗?

【在 n*******t 的大作中提到】
: for example:
: 我有两个function pointer, 分别指向两个不同function。
: complie的时候,这两个function pointer就得到function地址了吗?
: 可以用两个function pointer之差来indicate 系统stack 是upward 还是downward吗?
: FLAG的一个面试官说不可以,因为function pointer是compile time 得到地址的。
: stack 是runtime形成的。
: 然后把我往网上上的一个很popular的解法上引导。
: 但是网上所有关于这个解法的讨论都说,是因为compiler 优化造成compile time 的地
: 址和stack 无关。 这样,不是把gcc 的优化去掉,或者标成volatile不就可以了吗?
: 再问一个base class 和 相应 derived class的memory layout 能说明stack grow

g*********e
发帖数: 14401
4
当然是compile time得到的
当然runtime的时候load 到address space 里面,但他们的相对offset是不变的
k****i
发帖数: 128
5
有点迷惑,fp不是指向code section吗?stack是运行时call状态和fp有什么关系?
n*******7
发帖数: 181
6
基本概念不清啊。function pointer是runtime 变量,可以赋函数地址的值。函数地址
是compile time决定。stack方向应该看stack pointer,和function无关。

:for example:
:我有两个function pointer, 分别指向两个不同function。
s**x
发帖数: 7506
7
我觉得应该是运行时得到的,编译时不可能完全定下来,这个应该是由loader 分配的
。象共享 library, 可以同时被多个程序共享,同一函数在不同程序的地址会完全不同
,这个不可能编译时确定。
当然,这个跟stack 没关系。
k****5
发帖数: 546
8
function pointer is just the memory address of the function image in code
section. Once loaded in memory, it is not changed.
there can be more than one instance of one function on the stack, either
direct or indirect recursion.
Allocate some heap and stack variables, check their addresses to get the
idea of memory layout of heap&stack.
class is about data layout, not about stack.
check any compiler book about runtime structure etc.

【在 n*******t 的大作中提到】
: for example:
: 我有两个function pointer, 分别指向两个不同function。
: complie的时候,这两个function pointer就得到function地址了吗?
: 可以用两个function pointer之差来indicate 系统stack 是upward 还是downward吗?
: FLAG的一个面试官说不可以,因为function pointer是compile time 得到地址的。
: stack 是runtime形成的。
: 然后把我往网上上的一个很popular的解法上引导。
: 但是网上所有关于这个解法的讨论都说,是因为compiler 优化造成compile time 的地
: 址和stack 无关。 这样,不是把gcc 的优化去掉,或者标成volatile不就可以了吗?
: 再问一个base class 和 相应 derived class的memory layout 能说明stack grow

k****5
发帖数: 546
9
once you take the address of one function, I don't think it should be
optimized out like inlining etc. But the compiler usually choose to not save
frame pointer on stack by default. But that does not mean there's no such
function in memory in running time.

【在 k****5 的大作中提到】
: function pointer is just the memory address of the function image in code
: section. Once loaded in memory, it is not changed.
: there can be more than one instance of one function on the stack, either
: direct or indirect recursion.
: Allocate some heap and stack variables, check their addresses to get the
: idea of memory layout of heap&stack.
: class is about data layout, not about stack.
: check any compiler book about runtime structure etc.

n*******t
发帖数: 6
10
多谢大牛。
main() {
int a;
int b;
}
&b - &a >0 据说不能说明stack是up的,因为优化问题。

【在 k****5 的大作中提到】
: function pointer is just the memory address of the function image in code
: section. Once loaded in memory, it is not changed.
: there can be more than one instance of one function on the stack, either
: direct or indirect recursion.
: Allocate some heap and stack variables, check their addresses to get the
: idea of memory layout of heap&stack.
: class is about data layout, not about stack.
: check any compiler book about runtime structure etc.

1 (共1页)
进入JobHunting版参与讨论
相关主题
给大家看几道C 小程序heap&stack Linux vs. Windows  (转载)
onsite完了求bless~(附带点面经)F家电面
刚才看到小尾羊的一个面试题implement 3 stack in an array
A problem about Heap and Stack.LeetCode Jump Game [Runtime Error]
一道面试题Leetcode Copy List with Random Pointer Runtime Error?
stack grows upward or downward问leetcode上surrounded regions,新的test case出runtime error
请问Intel phone interview都会问那方便的问题?刚才电面,HM居然问我recruiter是怎么找到我的
请教一个问题,发两个包子。刚一遍最对NQueens,发个贴以自鼓励。
相关话题的讨论汇总
话题: function话题: pointer话题: stack话题: compile话题: time