由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Quant版 - chimbo面经里一道编程面试题
相关主题
chimbo 的一个编程题说起smart pointer
考个C++题学C++还是C#?
问个C++的问题一个C++问题
面试题,from Chimbo's tieC++ 题
问面试题金融公司的online test是选Java还是选C好?
面经C++ 110 题在精华区怎么找不到?
找工作结束了,随便写点吧請問怎麼照著碼工標準刷C++?
[合集] C++: operator new 为啥要是 static的, 不是有啥影响? (问个题
相关话题的讨论汇总
话题: class话题: layout话题: debugger话题: memory话题: pointer
进入Quant版参与讨论
1 (共1页)
a********e
发帖数: 508
1
这个题啥意思?难道在内存中不是class member按先后顺序存在的?
哪位能解释一下吗?谢谢
How to find out the memory layout of a class without initiate the class
P*****s
发帖数: 758
2
坐等chimbo大牛来解答。。。
c****o
发帖数: 1280
3
答案是俺也不确定,他就说set up a class pointer and point it to 0, and then
you
will know it. Never tried it myself though。。。。。。。。。。我当时就想问知
道了又
怎样???????????

【在 P*****s 的大作中提到】
: 坐等chimbo大牛来解答。。。
a********e
发帖数: 508
4
依然困惑中,得到一个null pointer然后怎么就知道了呢。。。

【在 c****o 的大作中提到】
: 答案是俺也不确定,他就说set up a class pointer and point it to 0, and then
: you
: will know it. Never tried it myself though。。。。。。。。。。我当时就想问知
: 道了又
: 怎样???????????

j********t
发帖数: 97
5
可能因为某些memory layout是compiler dependent的。比如virtual function的实现
standard C++没有明确规定,不同compiler实现可能有不同。多重继承也类似,另外编译器本身的一些优化,像alignment,也是depends。某些诡异的场合,才需要了解这些内部结构。
一般在debuger里看或者用特殊编译选项导出。这个NULL pointer也是在debugger里看的吗?
a********e
发帖数: 508
6
这个意思啊。试了一下,定义成null pointer确实可以看到
挺诡异的问题

编译器本身的一些优化,像alignment,也是depends。某些诡异的场合,才需要了解这
些内部结构。
看的吗?

【在 j********t 的大作中提到】
: 可能因为某些memory layout是compiler dependent的。比如virtual function的实现
: standard C++没有明确规定,不同compiler实现可能有不同。多重继承也类似,另外编译器本身的一些优化,像alignment,也是depends。某些诡异的场合,才需要了解这些内部结构。
: 一般在debuger里看或者用特殊编译选项导出。这个NULL pointer也是在debugger里看的吗?

y****e
发帖数: 28
7
So the answer of the original question is to first define a null pointer of
the class and then read the memory layout in the debugger.
I don't like the second part. Is it ever possible to get the memory layout
without using the debugger?
A very strange interview question.

【在 a********e 的大作中提到】
: 这个意思啊。试了一下,定义成null pointer确实可以看到
: 挺诡异的问题
:
: 编译器本身的一些优化,像alignment,也是depends。某些诡异的场合,才需要了解这
: 些内部结构。
: 看的吗?

j********t
发帖数: 97
8
Use -fdump-class-hierarchy flag for g++ to dump memory layout without
debugger.
http://cplusplus.co.il/2010/10/31/thunksgiving/
Or use /d1reportAllClassLayout for VC++.
http://thetweaker.wordpress.com/2010/11/07/d1reportallclasslayo

of

【在 y****e 的大作中提到】
: So the answer of the original question is to first define a null pointer of
: the class and then read the memory layout in the debugger.
: I don't like the second part. Is it ever possible to get the memory layout
: without using the debugger?
: A very strange interview question.

a********e
发帖数: 508
9
这个也太technical了吧。。。

【在 j********t 的大作中提到】
: Use -fdump-class-hierarchy flag for g++ to dump memory layout without
: debugger.
: http://cplusplus.co.il/2010/10/31/thunksgiving/
: Or use /d1reportAllClassLayout for VC++.
: http://thetweaker.wordpress.com/2010/11/07/d1reportallclasslayo
:
: of

1 (共1页)
进入Quant版参与讨论
相关主题
问个题问面试题
求期望值 (转载)面经
菜鸟请教积分问题找工作结束了,随便写点吧
有人了解MS foreign exchange strats吗?[合集] C++: operator new 为啥要是 static的, 不是有啥影响? (
chimbo 的一个编程题说起smart pointer
考个C++题学C++还是C#?
问个C++的问题一个C++问题
面试题,from Chimbo's tieC++ 题
相关话题的讨论汇总
话题: class话题: layout话题: debugger话题: memory话题: pointer