回答編集履歴
2
おのれC
answer
CHANGED
|
@@ -36,4 +36,27 @@
|
|
|
36
36
|
static int v2;//明示的に初期化されていない。値は0
|
|
37
37
|
```
|
|
38
38
|
|
|
39
|
-
となり、値は不定じゃないんですね。
|
|
39
|
+
となり、値は不定じゃないんですね。
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
あああ、C++に毒されていた。
|
|
44
|
+
|
|
45
|
+
そういえばCはstatic変数とconst修飾されている変数は別として(volatile修飾のときの扱いは忘れた)、変数の定義と同時じゃなくても最初の代入まで初期化という扱いでしたね、ちくせう。
|
|
46
|
+
|
|
47
|
+
```c
|
|
48
|
+
static int n1;//非明示的初期化
|
|
49
|
+
n1 = 2;//代入
|
|
50
|
+
static int n2;//非明示的初期化
|
|
51
|
+
int main(void)
|
|
52
|
+
{
|
|
53
|
+
int a;
|
|
54
|
+
a = 3;//Cだとこれも初期化
|
|
55
|
+
|
|
56
|
+
const int b = 0;//const修飾されているときは定義と同時にしか初期化できない
|
|
57
|
+
|
|
58
|
+
n2 = 3;//代入
|
|
59
|
+
|
|
60
|
+
return 0;
|
|
61
|
+
}
|
|
62
|
+
```
|
1
m
answer
CHANGED
|
@@ -18,10 +18,10 @@
|
|
|
18
18
|
|
|
19
19
|
> §6.7.9 Initialization
|
|
20
20
|
> 10 If an object that has automatic storage duration is not initialized explicitly, its value is
|
|
21
|
-
indeterminate. If an object that has static or thread storage duration is not initialized
|
|
21
|
+
indeterminate. **If an object that has static or thread storage duration is not initialized
|
|
22
|
-
explicitly, then:
|
|
22
|
+
explicitly**, then:
|
|
23
23
|
— if it has pointer type, it is initialized to a null pointer;
|
|
24
|
-
— if it has arithmetic type, it is initialized to (positive or unsigned) zero;
|
|
24
|
+
— **if it has arithmetic type, it is initialized to (positive or unsigned) zero;**
|
|
25
25
|
— if it is an aggregate, every member is initialized (recursively) according to these rules,
|
|
26
26
|
and any padding is initialized to zero bits;
|
|
27
27
|
— if it is a union, the first named member is initialized (recursively) according to these
|