回答編集履歴

1

コメントにしてたエラーケースの個数不足を修正し、実際のエラーを記載

2019/02/13 09:47

投稿

wwbQzhMkhhgEmhU
wwbQzhMkhhgEmhU

スコア343

test CHANGED
@@ -48,6 +48,42 @@
48
48
 
49
49
  {{2,3},{5,6}}, // 少ない
50
50
 
51
+ //{{2,3,4},{5,6,7,8}}, 多い。これはgcc 8.2.0だとエラー
52
+
53
+ {2,3,4,5,6,7}, // 古い書き方(普通)
54
+
55
+ {2,3,4,5,6}, // 古い書き方(少ない)
56
+
57
+ //{2,3,4,5,6,7,8} 古い書き方(多い)。これはgcc 8.2.0だとエラー
58
+
59
+ };
60
+
61
+
62
+
63
+ ```
64
+
65
+ ```text
66
+
67
+ user@lubuntu:~/cpp$ cat test.cpp
68
+
69
+ struct Vertex
70
+
71
+ {
72
+
73
+ float position[3];
74
+
75
+ float normal[3];
76
+
77
+ };
78
+
79
+
80
+
81
+ Vertex a[] = {
82
+
83
+ {{1,2,3},{4,5,6}}, // 普通
84
+
85
+ {{2,3},{5,6}}, // 少ない
86
+
51
87
  //{{2,3,4},{5,6,7}}, 多い。これはgcc 8.2.0だとエラー
52
88
 
53
89
  {2,3,4,5,6,7}, // 古い書き方(普通)
@@ -58,9 +94,71 @@
58
94
 
59
95
  };
60
96
 
61
-
97
+ int main() {return 0;}
98
+
62
-
99
+ user@lubuntu:~/cpp$ g++ -g test.cpp -o test
100
+
101
+ user@lubuntu:~/cpp$ gdb test
102
+
103
+ GNU gdb (Ubuntu 8.2-0ubuntu1) 8.2
104
+
105
+ Copyright (C) 2018 Free Software Foundation, Inc.
106
+
107
+ License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
108
+
109
+ This is free software: you are free to change and redistribute it.
110
+
111
+ There is NO WARRANTY, to the extent permitted by law.
112
+
113
+ Type "show copying" and "show warranty" for details.
114
+
115
+ This GDB was configured as "x86_64-linux-gnu".
116
+
117
+ Type "show configuration" for configuration details.
118
+
119
+ For bug reporting instructions, please see:
120
+
121
+ <http://www.gnu.org/software/gdb/bugs/>.
122
+
123
+ Find the GDB manual and other documentation resources online at:
124
+
125
+ <http://www.gnu.org/software/gdb/documentation/>.
126
+
127
+
128
+
129
+ For help, type "help".
130
+
131
+ Type "apropos word" to search for commands related to "word"...
132
+
133
+ Reading symbols from test...done.
134
+
135
+ (gdb) break main
136
+
137
+ Breakpoint 1 at 0x1129: file test.cpp, line 16.
138
+
139
+ (gdb) run
140
+
141
+ Starting program: /home/user/cpp/test
142
+
143
+
144
+
145
+ Breakpoint 1, main () at test.cpp:16
146
+
147
+ 16 int main() {return 0;}
148
+
149
+ (gdb) display a
150
+
151
+ 1: a = {{position = {1, 2, 3}, normal = {4, 5, 6}}, {position = {2, 3, 0}, normal = {5, 6, 0}}, {
152
+
153
+ position = {2, 3, 4}, normal = {5, 6, 7}}, {position = {2, 3, 4}, normal = {5, 6, 0}}}
154
+
155
+ (gdb)
156
+
63
- ```
157
+ ```
158
+
159
+
160
+
161
+ 多くてエラーになるケース(1)
64
162
 
65
163
  ```text
66
164
 
@@ -84,78 +182,78 @@
84
182
 
85
183
  {{2,3},{5,6}}, // 少ない
86
184
 
87
- //{{2,3,4},{5,6,7}}, 多い。これはgcc 8.2.0だとエラー
185
+ {{2,3,4},{5,6,7,8}},// 多い。これはgcc 8.2.0だとエラー
88
-
186
+
89
- {2,3,4,5,6,7}, // 古い書き方(普通)
187
+ {2,3,4,5,6,7}, // 古い書き方(普通)
90
-
188
+
91
- {2,3,4,5,6}, // 古い書き方(少ない)
189
+ {2,3,4,5,6}, // 古い書き方(少ない)
92
-
190
+
93
- //{2,3,4,5,6,7,8} 古い書き方(多い)。これはgcc 8.2.0だとエラー
191
+ //{2,3,4,5,6,7,8} // 古い書き方(多い)。これはgcc 8.2.0だとエラー
94
-
192
+
95
- };
193
+ };
194
+
195
+
96
196
 
97
197
  int main() {return 0;}
98
198
 
99
199
  user@lubuntu:~/cpp$ g++ -g test.cpp -o test
100
200
 
101
- user@lubuntu:~/cpp$ gdb test
102
-
103
- GNU gdb (Ubuntu 8.2-0ubuntu1) 8.2
104
-
105
- Copyright (C) 2018 Free Software Foundation, Inc.
106
-
107
- License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
108
-
109
- This is free software: you are free to change and redistribute it.
110
-
111
- There is NO WARRANTY, to the extent permitted by law.
112
-
113
- Type "show copying" and "show warranty" for details.
114
-
115
- This GDB was configured as "x86_64-linux-gnu".
116
-
117
- Type "show configuration" for configuration details.
118
-
119
- For bug reporting instructions, please see:
120
-
121
- <http://www.gnu.org/software/gdb/bugs/>.
122
-
123
- Find the GDB manual and other documentation resources online at:
124
-
125
- <http://www.gnu.org/software/gdb/documentation/>.
126
-
127
-
128
-
129
- For help, type "help".
130
-
131
- Type "apropos word" to search for commands related to "word"...
132
-
133
- Reading symbols from test...done.
134
-
135
- (gdb) break main
136
-
137
- Breakpoint 1 at 0x1129: file test.cpp, line 16.
138
-
139
- (gdb) run
140
-
141
- Starting program: /home/user/cpp/test
142
-
143
-
144
-
145
- Breakpoint 1, main () at test.cpp:16
146
-
147
- 16 int main() {return 0;}
148
-
149
- (gdb) display a
150
-
151
- 1: a = {{position = {1, 2, 3}, normal = {4, 5, 6}}, {position = {2, 3, 0}, normal = {5, 6, 0}}, {
152
-
153
- position = {2, 3, 4}, normal = {5, 6, 7}}, {position = {2, 3, 4}, normal = {5, 6, 0}}}
154
-
155
- (gdb)
156
-
157
-
158
-
159
-
160
-
161
- ```
201
+ test.cpp:14:1: error: too many initializers for ‘float [3]’
202
+
203
+ };
204
+
205
+ ^
206
+
207
+ user@lubuntu:~/cpp$
208
+
209
+ ```
210
+
211
+ 多くてエラーになるケース(2)
212
+
213
+ ```text
214
+
215
+ user@lubuntu:~/cpp$ cat test.cpp
216
+
217
+ struct Vertex
218
+
219
+ {
220
+
221
+ float position[3];
222
+
223
+ float normal[3];
224
+
225
+ };
226
+
227
+
228
+
229
+ Vertex a[] = {
230
+
231
+ {{1,2,3},{4,5,6}}, // 普通
232
+
233
+ {{2,3},{5,6}}, // 少ない
234
+
235
+ //{{2,3,4},{5,6,7,8}}, 多い。これはgcc 8.2.0だとエラー
236
+
237
+ {2,3,4,5,6,7}, // 古い書き方(普通)
238
+
239
+ {2,3,4,5,6}, // 古い書き方(少ない)
240
+
241
+ {2,3,4,5,6,7,8} // 古い書き方(多い)。これはgcc 8.2.0だとエラー
242
+
243
+ };
244
+
245
+
246
+
247
+ int main() {return 0;}
248
+
249
+ user@lubuntu:~/cpp$ g++ -g test.cpp -o test
250
+
251
+ test.cpp:14:1: error: too many initializers for ‘Vertex’
252
+
253
+ };
254
+
255
+ ^
256
+
257
+ user@lubuntu:~/cpp$
258
+
259
+ ```