質問編集履歴
2
プログラムの修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -37,9 +37,9 @@
|
|
37
37
|
|
38
38
|
// C言語による簡易vectorもどき
|
39
39
|
typedef struct cvector_t {
|
40
|
-
void* data_
|
40
|
+
void* data_; // 要素の格納領域
|
41
|
-
int capacity_
|
41
|
+
int capacity_; // 格納可能な最大要素数
|
42
|
-
int size_
|
42
|
+
int size_; // 格納されている要素数
|
43
43
|
} cvector;
|
44
44
|
|
45
45
|
// 初期化
|
1
構造体の初期化についてC言語で動作するよう修正しました
title
CHANGED
File without changes
|
body
CHANGED
@@ -16,7 +16,7 @@
|
|
16
16
|
int main(void)
|
17
17
|
{
|
18
18
|
cvector test;
|
19
|
-
|
19
|
+
INIT(test);
|
20
20
|
int size = 20;
|
21
21
|
for (int i = 0; i < size; i++) {
|
22
22
|
PUSH_BACK(int, test, i * i);
|
@@ -42,6 +42,9 @@
|
|
42
42
|
int size_ = 0; // 格納されている要素数
|
43
43
|
} cvector;
|
44
44
|
|
45
|
+
// 初期化
|
46
|
+
#define INIT(CVECTOR) CVECTOR.data_ = 0; CVECTOR.capacity_ = 0; CVECTOR.size_ = 0;
|
47
|
+
|
45
48
|
// 配列への参照(汎用)
|
46
49
|
#define ARRAY_AT(T, V, N) ((T*)V)[N]
|
47
50
|
|