回答編集履歴

3

operator

2017/07/23 06:54

投稿

yumetodo
yumetodo

スコア5850

test CHANGED
@@ -34,7 +34,7 @@
34
34
 
35
35
 
36
36
 
37
- ちなみにどこを指しているかわからない or NULL pointerはdereferenceしてはいけません。
37
+ ちなみにどこを指しているかわからない or NULL pointerはdereferenceしてはいけません。dereferenceとは具体的に言うと、`operator *`(単項演算子), `operator []`の呼び出しです。
38
38
 
39
39
 
40
40
 

2

UB

2017/07/23 06:54

投稿

yumetodo
yumetodo

スコア5850

test CHANGED
@@ -52,12 +52,20 @@
52
52
 
53
53
  *p1;//OK
54
54
 
55
- //*p2;//NG
55
+ //*p2;//NG: Undefined Behavior: C11, 6.5.3.2p4
56
56
 
57
- //*p3;//NG
57
+ //*p3;//NG: Undefined Behavior: C11, 6.5.3.2p4
58
58
 
59
59
  *p4;//OK
60
60
 
61
61
  free(p4);
62
62
 
63
63
  ```
64
+
65
+
66
+
67
+ ref:
68
+
69
+
70
+
71
+ - [c++ - Is dereferencing a pointer that's equal to nullptr undefined behavior by the standard? - Stack Overflow](https://stackoverflow.com/questions/28573215/is-dereferencing-a-pointer-thats-equal-to-nullptr-undefined-behavior-by-the-sta)

1

追記

2017/07/23 05:37

投稿

yumetodo
yumetodo

スコア5850

test CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
 
8
8
 
9
- ```cpp
9
+ ```c
10
10
 
11
11
  int x;//格納する場所
12
12
 
@@ -19,3 +19,45 @@
19
19
 
20
20
 
21
21
  ここで上例で`x_p`のみの状態が誤回答の状態です。どこを指しているか不明なポインタを渡しています。
22
+
23
+
24
+
25
+ # 追記
26
+
27
+
28
+
29
+ > ポインタはあらかじめ格納する場所を用意しておく必要があるということですか?
30
+
31
+
32
+
33
+ じゃないと何を指し示すのか(point)わからないじゃないですか。
34
+
35
+
36
+
37
+ ちなみにどこを指しているかわからない or NULL pointerはdereferenceしてはいけません。
38
+
39
+
40
+
41
+ ```c
42
+
43
+ int x;
44
+
45
+ int* p1 = &x;
46
+
47
+ int* p2;
48
+
49
+ int* p3 = NULL;
50
+
51
+ int* p4 = malloc(sizof(int));
52
+
53
+ *p1;//OK
54
+
55
+ //*p2;//NG
56
+
57
+ //*p3;//NG
58
+
59
+ *p4;//OK
60
+
61
+ free(p4);
62
+
63
+ ```