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类型……语法上没问题,
语义上就难说了…… |
|