由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - c++: how to convert interger to pointer?
相关主题
Nvidia 3rd phone interview and Amazon offer一道题目
回馈本版,贴ms onsite面经谁给改一个线程安全的smarter pointer类
问个C++问题一个简单的java题
面试面试官错了怎么办?My Microsoft Phone Interview
说一下pressure interview。。。今早Bloomberg电话面试经过,奉献给大家。。。
一个下午悲剧两次MathWorks被拒
C++ Q93 - Q95关于Bloomberg Phone Interview
谁对design pattern比较熟?请教个C++编程思路
相关话题的讨论汇总
话题: cast话题: c++话题: interger话题: pointer
进入JobHunting版参与讨论
1 (共1页)
a****f
发帖数: 944
1
A phone interview question. I said using reinterpret_cast, but he said no.
Does any one know the correct answer? I wasn't a CS major so I know little
about fundamental C++.
C***y
发帖数: 2546
2
直接强制转换就行了
比如说加(int *)
如果在C++中的话,可以加static_cast

【在 a****f 的大作中提到】
: A phone interview question. I said using reinterpret_cast, but he said no.
: Does any one know the correct answer? I wasn't a CS major so I know little
: about fundamental C++.

a****f
发帖数: 944
3
Thanks.
Then was my answer (reinterpret_cast) wrong? if so what's wrong with it?

【在 C***y 的大作中提到】
: 直接强制转换就行了
: 比如说加(int *)
: 如果在C++中的话,可以加static_cast

d*****d
发帖数: 46
4
I agree with you. in c++, we should use reinterpret_cast.

【在 a****f 的大作中提到】
: Thanks.
: Then was my answer (reinterpret_cast) wrong? if so what's wrong with it?

l*****g
发帖数: 685
5
reinterpret_cast和直接用hard cast都应该可以啊
(至于得到的 pointer address是不是有效,那是另一回事)
如果反过来,把pointer convert 成 int, 那得考虑是32位还是64位的系统。如果是64
位的,那convert to int 会有loss

【在 a****f 的大作中提到】
: A phone interview question. I said using reinterpret_cast, but he said no.
: Does any one know the correct answer? I wasn't a CS major so I know little
: about fundamental C++.

l*****g
发帖数: 685
6
static_cast不行的
static_cast必须在匹配的类型之间,不能把bits随意cast成任何类型

【在 C***y 的大作中提到】
: 直接强制转换就行了
: 比如说加(int *)
: 如果在C++中的话,可以加static_cast

C***y
发帖数: 2546
7
试了一下
的确不行
什么样才叫匹配的类型?
谢谢

【在 l*****g 的大作中提到】
: static_cast不行的
: static_cast必须在匹配的类型之间,不能把bits随意cast成任何类型

r********g
发帖数: 1351
8
就是float->int, char->int这类的吧,编译器可以自动转换的类型,加上static cast
是为了防止
bug和理解方便。

【在 C***y 的大作中提到】
: 试了一下
: 的确不行
: 什么样才叫匹配的类型?
: 谢谢

C***y
发帖数: 2546
9
thanks

cast

【在 r********g 的大作中提到】
: 就是float->int, char->int这类的吧,编译器可以自动转换的类型,加上static cast
: 是为了防止
: bug和理解方便。

F**********r
发帖数: 237
10
static_cast can be used when the compiler can do the conversion
automatically(with a warning msg). imho reinterpret_cast is the only way. no
?
1 (共1页)
进入JobHunting版参与讨论
相关主题
请教个C++编程思路说一下pressure interview。。。
问道编程题一个下午悲剧两次
明天ONSITE攒人品,发面试知识点总结!!C++ Q93 - Q95
bloomberg就85k?谁对design pattern比较熟?
Nvidia 3rd phone interview and Amazon offer一道题目
回馈本版,贴ms onsite面经谁给改一个线程安全的smarter pointer类
问个C++问题一个简单的java题
面试面试官错了怎么办?My Microsoft Phone Interview
相关话题的讨论汇总
话题: cast话题: c++话题: interger话题: pointer