回答編集履歴

1

値について追記

2020/05/14 13:23

投稿

SHOMI
SHOMI

スコア4079

test CHANGED
@@ -1 +1,17 @@
1
- `*(unsigned short *)&data[ulcnt]`はポインタ(`&data[ulcnt]`)の指す先を`unsigned short`(符号なし2バイト整数)の値として読んでいます
1
+ `*(unsigned short *)&data[ulcnt]`はポインタ(`&data[ulcnt]`)の指す先を`unsigned short`(符号なし2バイト整数)の値として読んでいます
2
+
3
+
4
+
5
+ > (unsigned short *)&data[ulcnt] はポインタであるのはわかっているのですが、
6
+
7
+ そのポインタが指す内容が一体どこなのかが分らずにいます。
8
+
9
+
10
+
11
+ ポインタ自体は同じアドレスを指しています。
12
+
13
+ `unsigned short`のポインタとなる為、`*(unsigned short *)&data[ulcnt]`とすると2バイト読み取るのです。
14
+
15
+ リトルエンディアン環境:`data[ulcnt] + data[ulcnt+1] * 256`
16
+
17
+ ビッグエンディアン環境:`data[ulcnt] * 256 + data[ulcnt+1]`