2014-10-18 43 views

回答

1

整件事得到一个指向数组中k32 nd元素后半部分的指针。

数组元素是long longlong long的一半是long。下半部分是通过将long long *指针投射到long *然后递增1找到的。这给了你一个指向下半部分的指针。

  a64[k32]  // the k32'nd element of the array  type: long long 
      &a64[k32]  // address of the k32'nd element  type: long long * 
(long *) &a64[k32]  // that address re-cast to long *  type: long * 
((long *) &a64[k32] + 1) // the second half of the k32'nd item type: long * 

这不是完全便携的。使用int32_tint64_t而不是longlong long会更安全。它也假设一个特定的排列顺序。

+0

啊我明白了,天才!谢谢约翰! – thoughtMaze 2014-10-18 02:05:49

+0

k32没有设置,所以整件事都是未定义的行为。 “漫长的一半很长” - 不一定。 http://www.unix.org/version2/whatsnew/lp64_wp.html – 2014-10-18 05:11:06