由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - a question about CAST
相关主题
C++ 的 问题typedef
c++标准函数传递一问c++ dynamic cast
static initialization dependency c++Test your C++ knowledge...
C arrayC++ question
码工试题 (转载)a C++ question
A C++ compiler related interview question如何 initialize array member?
c++ initialize struct问一个 copy constructor 的问题 (C++)
what's wrong with this C++ code?question about c++ constructor
相关话题的讨论汇总
话题: cast话题: foo话题: temp话题: double话题: address
进入Programming版参与讨论
1 (共1页)
l***g
发帖数: 1035
1
// is the following code compilable? is the cast operating on the value (tem
p) or the address?
int temp = 2;
...
foo((double)&temp);
k**f
发帖数: 372
2

tem
My understanding is that you are trying to cast an address to an integer to
a double, which is hardly correct.
If foo() expects an address to a double as its input, you need to declare an
intermediate variable, say x, of type double, initialized to the value of
temp, and then call foo() with the address of x: foo(&x). If foo modifies
its input, you can then assign x to temp (may loss fractional part, though).

【在 l***g 的大作中提到】
: // is the following code compilable? is the cast operating on the value (tem
: p) or the address?
: int temp = 2;
: ...
: foo((double)&temp);

n****g
发帖数: 150
3
works well on C/C++ compilers, nothing wrong with it.
h******e
发帖数: 26
4
语句的意思是把temp变量的“地址”转换为double类型
“地址”这东西通常是32/64位的整数,把这个转换为double类型……语法上没问题,
语义上就难说了……
1 (共1页)
进入Programming版参与讨论
相关主题
question about c++ constructor码工试题 (转载)
问一个简单C++问题A C++ compiler related interview question
A tech question (转载)c++ initialize struct
why int** cannot convert to const int** ?what's wrong with this C++ code?
C++ 的 问题typedef
c++标准函数传递一问c++ dynamic cast
static initialization dependency c++Test your C++ knowledge...
C arrayC++ question
相关话题的讨论汇总
话题: cast话题: foo话题: temp话题: double话题: address