由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - virtual table存在memory的哪块啊?
相关主题
C++ Q36: derivation specification (B8_9)C++ Q42: (C22)
问一个C++问题:default parameter and overriding/inheritancMathworks is hiring! job #10319 - C++ Developer – Compile
问一道inline function的题目Compiler/C++ position @Mathworks
Bloomberg(financial software developer)第一轮面试how can MS-DOS bind address at compile time?
问一个C的简单问题[合集] 几个面试中碰到的问题
bloomberg电面2,攒rp求bless (给据了 :()一个c++题(exception handling)
C++ 一题virtual destructor的地址在virtual table里面吗?
C++ templateQ in C/C++
相关话题的讨论汇总
话题: virtual话题: segment话题: table话题: code话题: data
进入JobHunting版参与讨论
1 (共1页)
t**e
发帖数: 208
1
每个类都有一个virtual table, 这个table是存在code segment 还是data segment?
谢谢~~
a**********s
发帖数: 588
2
I think it doesn't matter but shouldn't be in the code segment... I guess
it's in the constant portion of data segment.
Q******e
发帖数: 85
3
More effective C++ 说了,通常virtual table is generated in the object file
containing the definition of the first non-inline non-pure virtual function
in that class. 我认为virtual table应该在代码段。
a**********s
发帖数: 588
4
It was talking about something else.
Consider if it were kept in the code segment, how could the compiler generate code to do dynamic binding - it needs to calculate the entrance address to know where to jump to.

function

【在 Q******e 的大作中提到】
: More effective C++ 说了,通常virtual table is generated in the object file
: containing the definition of the first non-inline non-pure virtual function
: in that class. 我认为virtual table应该在代码段。

Q******e
发帖数: 85
5
Dynamic binding is decided by the actual object type. suppose Base* ptr =
new Derived. ptr actually point to a Derived object and compiler knows it.
Through ptr,we can get virtual table pointer vptr (the code segment address)
of Derived object. When running, the virtual function can be found through
vptr with virtual function index (offset). In that way, we have dynamic
binding.
a**********s
发帖数: 588
6
Just to write a simple program
#include
class Base
{
public:
virtual int drive() { return 0; }
};
class Derived : public Base
{
public:
int drive() { return 1; }
};
int main()
{
Base* p = new Derived();
std::cout << p->drive() << std::endl;
delete p;
return 0;
}
Q******e
发帖数: 85
7
So? what is the purpose of your code?
a**********s
发帖数: 588
8
And the generated assembly, I am showing the const data segment only:
a**********s
发帖数: 588
9
hmm, I found it's bely hard to convince people :(
Q******e
发帖数: 85
10
Actually, using the dynamic binding method, we can put the code inside data
segment. But why we want to break the traditional routine? data is data,
code is code.
相关主题
bloomberg电面2,攒rp求bless (给据了 :()C++ Q42: (C22)
C++ 一题Mathworks is hiring! job #10319 - C++ Developer – Compile
C++ templateCompiler/C++ position @Mathworks
进入JobHunting版参与讨论
Q******e
发帖数: 85
11
using g++ -S, you can find immediate code with Assembly language.
a**********s
发帖数: 588
12
That's intermediate assembly. No clear concept of code/text segments.
However, when you look carefully, you still see virtual tables are
declared as data there.

【在 Q******e 的大作中提到】
: using g++ -S, you can find immediate code with Assembly language.
a**********s
发帖数: 588
13
What are you talking about.. You think virtual table is code??? How could
dynamic binding permit you to do this??

data

【在 Q******e 的大作中提到】
: Actually, using the dynamic binding method, we can put the code inside data
: segment. But why we want to break the traditional routine? data is data,
: code is code.

M*****a
发帖数: 2054
14
I agree with u
in fact, class is an object, virtual table should be data
but it maybe const data

【在 a**********s 的大作中提到】
: What are you talking about.. You think virtual table is code??? How could
: dynamic binding permit you to do this??
:
: data

Q******e
发帖数: 85
15
My fault, I always think the topic is about where to put the virtual
function. I should watch carefully about the topic. Sorry.
s*****e
发帖数: 60
16
I think it depends on the implementation of compiler.
1 (共1页)
进入JobHunting版参与讨论
相关主题
Q in C/C++问一个C的简单问题
求救:第一次电话面试bloomberg电面2,攒rp求bless (给据了 :()
一个电面C++ 一题
问个C/C++概念的问题C++ template
C++ Q36: derivation specification (B8_9)C++ Q42: (C22)
问一个C++问题:default parameter and overriding/inheritancMathworks is hiring! job #10319 - C++ Developer – Compile
问一道inline function的题目Compiler/C++ position @Mathworks
Bloomberg(financial software developer)第一轮面试how can MS-DOS bind address at compile time?
相关话题的讨论汇总
话题: virtual话题: segment话题: table话题: code话题: data