這將依賴機器的字節順序在其上運行。這是非常糟糕的做法。 在一個小的endian系統上,這是大多數Intel硬件,最低位的字節是第一位,因此32位SIGNED值將寫入64位整數的低32位。在一個大的endian系統中,它將被寫入高位。
注意,INT簽署。如果value2是負值,則生成的64位數不會爲負數(除非它已爲負數)。
它也不會改變64位整數的高位。
我說...不這樣做呢?
編輯 爲了更直接地回答你的問題,是的,你是對的,這取決於你的意思是「前32位」。首先以平臺使用的任何順序,是的。
&value1 -> will give the address of value1
(int32_t*)&value1 -> tells the compiler to treat the address of value1 as a pointer to an int32_t
*(int32_t*)&value1 -> then dereference the pointer, so assigning to this will put the assigned value into the address of value1 as if it were an int32_t.
這是關於字節序。之前有太多關於這方面的問題 –