質問編集履歴
2
修正したがまだコンパイルできないので、再投稿
test
CHANGED
File without changes
|
test
CHANGED
@@ -40,15 +40,27 @@
|
|
40
40
|
|
41
41
|
---
|
42
42
|
|
43
|
-
追記
|
43
|
+
追記 : 16/10/10
|
44
|
+
|
44
|
-
|
45
|
+
教えて頂いた通りに修正しましたがまだ、コンパイルができず、実行ファイルができません。
|
46
|
+
|
45
|
-
|
47
|
+
修正したコードと実行結果を載せますのでよろしくお願いします。
|
46
48
|
|
47
49
|
|
48
50
|
|
49
51
|
07_01.c
|
50
52
|
|
53
|
+
```
|
54
|
+
|
55
|
+
#include <stdlib.h>
|
56
|
+
|
57
|
+
#include <unistd.h>
|
58
|
+
|
59
|
+
#include <fcntl.h>
|
60
|
+
|
61
|
+
#include <signal.h>
|
62
|
+
|
51
|
-
|
63
|
+
#include <sys/time.h>
|
52
64
|
|
53
65
|
#define DATA_FILENAME "./stopwatch.dat"
|
54
66
|
|
@@ -70,7 +82,7 @@
|
|
70
82
|
|
71
83
|
return -1;
|
72
84
|
|
73
|
-
if(
|
85
|
+
if(write(fd,startTime,sizeof(*startTime))!=sizeof(*startTime))
|
74
86
|
|
75
87
|
ret=-1;
|
76
88
|
|
@@ -88,17 +100,29 @@
|
|
88
100
|
|
89
101
|
```
|
90
102
|
|
103
|
+
#include <stdlib.h>
|
104
|
+
|
105
|
+
#include <unistd.h>
|
106
|
+
|
107
|
+
#include <sys/time.h>
|
108
|
+
|
109
|
+
#include <fcntl.h>
|
110
|
+
|
111
|
+
#include <signal.h>
|
112
|
+
|
113
|
+
#define DATA_FILENAME "./stopwatch.dat"
|
114
|
+
|
91
115
|
int restoreTime(struct timeval *startTime)
|
92
116
|
|
93
117
|
{
|
94
118
|
|
95
|
-
int f
|
119
|
+
int fd,ret=0;
|
96
120
|
|
97
121
|
if((fd=open(DATA_FILENAME,O_RDONLY))<0)
|
98
122
|
|
99
123
|
return -1;
|
100
124
|
|
101
|
-
if(read(fd,strtTime,sizeof(*startTime))!=sizeof(*startTime))
|
125
|
+
if(read(fd,startTime,sizeof(*startTime))!=sizeof(*startTime))
|
102
126
|
|
103
127
|
ret =-1;
|
104
128
|
|
@@ -116,6 +140,20 @@
|
|
116
140
|
|
117
141
|
```
|
118
142
|
|
143
|
+
#include <stdlib.h>
|
144
|
+
|
145
|
+
#include <unistd.h>
|
146
|
+
|
147
|
+
#include <sys/time.h>
|
148
|
+
|
149
|
+
#include <fcntl.h>
|
150
|
+
|
151
|
+
#include <signal.h>
|
152
|
+
|
153
|
+
int restoreTime(struct timeval *startTime);
|
154
|
+
|
155
|
+
void printDiff(struct timeval *t1,struct timeval *t2);
|
156
|
+
|
119
157
|
void lastTime(int unused)
|
120
158
|
|
121
159
|
{
|
@@ -126,7 +164,7 @@
|
|
126
164
|
|
127
165
|
if(restoreTime(&startTime)<0)
|
128
166
|
|
129
|
-
exit(EXIT_FAILRE);
|
167
|
+
exit(EXIT_FAILURE);
|
130
168
|
|
131
169
|
gettimeofday(&lastTime,NULL);
|
132
170
|
|
@@ -144,6 +182,18 @@
|
|
144
182
|
|
145
183
|
```
|
146
184
|
|
185
|
+
#include <stdio.h>
|
186
|
+
|
187
|
+
#include <stdlib.h>
|
188
|
+
|
189
|
+
#include <unistd.h>
|
190
|
+
|
191
|
+
#include <sys/time.h>
|
192
|
+
|
193
|
+
#include <fcntl.h>
|
194
|
+
|
195
|
+
#include <signal.h>
|
196
|
+
|
147
197
|
void printDiff(struct timeval *t1,struct timeval *t2)
|
148
198
|
|
149
199
|
{
|
@@ -170,21 +220,23 @@
|
|
170
220
|
|
171
221
|
main.c
|
172
222
|
|
223
|
+
```
|
224
|
+
|
173
|
-
|
225
|
+
#include <stdio.h>
|
174
|
-
|
226
|
+
|
175
|
-
#include <stdlib.h>
|
227
|
+
#include <stdlib.h>
|
176
|
-
|
228
|
+
|
177
|
-
#include <unistd.h>
|
229
|
+
#include <unistd.h>
|
178
|
-
|
230
|
+
|
179
|
-
#include <sys/time.h>
|
231
|
+
#include <sys/time.h>
|
180
|
-
|
232
|
+
|
181
|
-
#include <fcntl.h>
|
233
|
+
#include <fcntl.h>
|
182
|
-
|
234
|
+
|
183
|
-
#include <signal.h>
|
235
|
+
#include <signal.h>
|
184
|
-
|
185
|
-
|
186
|
-
|
236
|
+
|
237
|
+
|
238
|
+
|
187
|
-
int iniTime(struct timeval *startTime);
|
239
|
+
int initTime(struct timeval *startTime);
|
188
240
|
|
189
241
|
int restoreTime(struct timeval *startTime);
|
190
242
|
|
@@ -280,221 +332,11 @@
|
|
280
332
|
|
281
333
|
$ gcc 07_01.c 07_02.c 07_04.c 07_05.c main.c
|
282
334
|
|
283
|
-
07_01.c: In function ‘iniTime’:
|
284
|
-
|
285
|
-
07_01.c:8:25: error: ‘NULL’ undeclared (first use in this function)
|
286
|
-
|
287
|
-
gettimeofday(startTime,NULL);
|
288
|
-
|
289
|
-
^
|
290
|
-
|
291
|
-
07_01.c:8:25: note: each undeclared identifier is reported only once for each function it appears in
|
292
|
-
|
293
|
-
07_01.c:10:9: warning: implicit declaration of function ‘open’ [-Wimplicit-function-declaration]
|
294
|
-
|
295
|
-
if((fd=open(DATA_FILENAME,O_WRONLY|O_CREAT|O_TRUNC,0644))<0)
|
296
|
-
|
297
|
-
^
|
298
|
-
|
299
|
-
07_01.c:10:28: error: ‘O_WRONLY’ undeclared (first use in this function)
|
300
|
-
|
301
|
-
if((fd=open(DATA_FILENAME,O_WRONLY|O_CREAT|O_TRUNC,0644))<0)
|
302
|
-
|
303
|
-
^
|
304
|
-
|
305
|
-
07_01.c:10:37: error: ‘O_CREAT’ undeclared (first use in this function)
|
306
|
-
|
307
|
-
if((fd=open(DATA_FILENAME,O_WRONLY|O_CREAT|O_TRUNC,0644))<0)
|
308
|
-
|
309
|
-
^
|
310
|
-
|
311
|
-
07_01.c:10:45: error: ‘O_TRUNC’ undeclared (first use in this function)
|
312
|
-
|
313
|
-
if((fd=open(DATA_FILENAME,O_WRONLY|O_CREAT|O_TRUNC,0644))<0)
|
314
|
-
|
315
|
-
^
|
316
|
-
|
317
|
-
07_01.c:12:5: warning: implicit declaration of function ‘Write’ [-Wimplicit-function-declaration]
|
318
|
-
|
319
|
-
if(Write(fd,startTime,sizeof(*startTime))!=sizeof(*startTime))
|
320
|
-
|
321
|
-
^
|
322
|
-
|
323
|
-
07_01.c:14:2: warning: implicit declaration of function ‘close’ [-Wimplicit-function-declaration]
|
324
|
-
|
325
|
-
close(fd);
|
326
|
-
|
327
|
-
^
|
328
|
-
|
329
|
-
07_02.c:1:24: warning: ‘struct timeval’ declared inside parameter list
|
330
|
-
|
331
|
-
int restoreTime(struct timeval *startTime)
|
332
|
-
|
333
|
-
^
|
334
|
-
|
335
|
-
07_02.c:1:24: warning: its scope is only this definition or declaration, which is probably not what you want
|
336
|
-
|
337
|
-
07_02.c: In function ‘restoreTime’:
|
338
|
-
|
339
|
-
07_02.c:4:6: error: ‘fd’ undeclared (first use in this function)
|
340
|
-
|
341
|
-
i
|
335
|
+
/tmp/cc8inniA.o: 関数 `main' 内:
|
342
|
-
|
343
|
-
|
336
|
+
|
344
|
-
|
345
|
-
07_02.c:4:6: note: each undeclared identifier is reported only once for each function it appears in
|
346
|
-
|
347
|
-
07_02.c:4:9: warning: implicit declaration of function ‘open’ [-Wimplicit-function-declaration]
|
348
|
-
|
349
|
-
if((fd=open(DATA_FILENAME,O_RDONLY))<0)
|
350
|
-
|
351
|
-
^
|
352
|
-
|
353
|
-
07_02.c:4:14: error: ‘DATA_FILENAME’ undeclared (first use in this function)
|
354
|
-
|
355
|
-
if((fd=open(DATA_FILENAME,O_RDONLY))<0)
|
356
|
-
|
357
|
-
^
|
358
|
-
|
359
|
-
07_02.c:4:28: error: ‘O_RDONLY’ undeclared (first use in this function)
|
360
|
-
|
361
|
-
if((fd=open(DATA_FILENAME,O_RDONLY))<0)
|
362
|
-
|
363
|
-
^
|
364
|
-
|
365
|
-
07_02.c:6:5: warning: implicit declaration of function ‘read’ [-Wimplicit-function-declaration]
|
366
|
-
|
367
|
-
if(read(fd,strtTime,sizeof(*startTime))!=sizeof(*startTime))
|
368
|
-
|
369
|
-
^
|
370
|
-
|
371
|
-
07_02.c:6:13: error: ‘strtTime’ undeclared (first use in this function)
|
372
|
-
|
373
|
-
if(read(fd,strtTime,sizeof(*startTime))!=sizeof(*startTime))
|
374
|
-
|
375
|
-
^
|
376
|
-
|
377
|
-
07_02.c:6:29: error: dereferencing pointer to incomplete type ‘struct timeval’
|
378
|
-
|
379
|
-
if(read(fd,strtTime,sizeof(*startTime))!=sizeof(*startTime))
|
380
|
-
|
381
|
-
^
|
382
|
-
|
383
|
-
07_02.c:8:2: warning: implicit declaration of function ‘close’ [-Wimplicit-function-declaration]
|
384
|
-
|
385
|
-
close(fd);
|
386
|
-
|
387
|
-
^
|
388
|
-
|
389
|
-
07_04.c: In function ‘lastTime’:
|
390
|
-
|
391
|
-
07_04.c:3:17: error: storage size of ‘startTime’ isn’t known
|
392
|
-
|
393
|
-
struct timeval startTime,lastTime;
|
394
|
-
|
395
|
-
^
|
396
|
-
|
397
|
-
07_04.c:3:27: error: storage size of ‘lastTime’ isn’t known
|
398
|
-
|
399
|
-
struct timeval startTime,lastTime;
|
400
|
-
|
401
|
-
^
|
402
|
-
|
403
|
-
07_04.c:5:5: warning: implicit declaration of function ‘restoreTime’ [-Wimplicit-function-declaration]
|
404
|
-
|
405
|
-
if(restoreTime(&startTime)<0)
|
406
|
-
|
407
|
-
^
|
408
|
-
|
409
|
-
07_04.c:6:3: warning: implicit declaration of function ‘exit’ [-Wimplicit-function-declaration]
|
410
|
-
|
411
|
-
exit(EXIT_FAILRE);
|
412
|
-
|
413
|
-
^
|
414
|
-
|
415
|
-
07_04.c:6:3: warning: incompatible implicit declaration of built-in function ‘exit’
|
416
|
-
|
417
|
-
07_04.c:6:3: note: include ‘<stdlib.h>’ or provide a declaration of ‘exit’
|
418
|
-
|
419
|
-
07_04.c:6:8: error: ‘EXIT_FAILRE’ undeclared (first use in this function)
|
420
|
-
|
421
|
-
exit(EXIT_FAILRE);
|
422
|
-
|
423
|
-
^
|
424
|
-
|
425
|
-
07_04.c:6:8: note: each undeclared identifier is reported only once for each function it appears in
|
426
|
-
|
427
|
-
07_04.c:7:2: warning: implicit declaration of function ‘gettimeofday’ [-Wimplicit-function-declaration]
|
428
|
-
|
429
|
-
gettimeofday(&lastTime,NULL);
|
430
|
-
|
431
|
-
^
|
432
|
-
|
433
|
-
07_04.c:7:25: error: ‘NULL’ undeclared (first use in this function)
|
434
|
-
|
435
|
-
gettimeofday(&lastTime,NULL);
|
436
|
-
|
437
|
-
^
|
438
|
-
|
439
|
-
07_04.c:8:2: warning: implicit declaration of function ‘printDiff’ [-Wimplicit-function-declaration]
|
440
|
-
|
441
|
-
|
337
|
+
main.c:(.text+0x4a): `initTime' に対する定義されていない参照です
|
442
|
-
|
443
|
-
|
338
|
+
|
444
|
-
|
445
|
-
07_04.c:9:2: warning: incompatible implicit declaration of built-in function ‘exit’
|
446
|
-
|
447
|
-
exit(EXIT_SUCCESS);
|
448
|
-
|
449
|
-
^
|
450
|
-
|
451
|
-
07_04.c:9:2: note: include ‘<stdlib.h>’ or provide a declaration of ‘exit’
|
452
|
-
|
453
|
-
07_04.c:9:7: error: ‘EXIT_SUCCESS’ undeclared (first use in this function)
|
454
|
-
|
455
|
-
exit(EXIT_SUCCESS);
|
456
|
-
|
457
|
-
^
|
458
|
-
|
459
|
-
07_05.c:1:42: warning: ‘struct timeval’ declared inside parameter list
|
460
|
-
|
461
|
-
void printDiff(struct timeval *t1,struct timeval *t2)
|
462
|
-
|
463
|
-
^
|
464
|
-
|
465
|
-
07_05.c:1:42: warning: its scope is only this definition or declaration, which is probably not what you want
|
466
|
-
|
467
|
-
07_05.c: In function ‘printDiff’:
|
468
|
-
|
469
|
-
|
339
|
+
collect2: error: ld returned 1 exit status
|
470
|
-
|
471
|
-
struct timeval diff;
|
472
|
-
|
473
|
-
^
|
474
|
-
|
475
|
-
07_05.c:5:2: warning: implicit declaration of function ‘timersub’ [-Wimplicit-function-declaration]
|
476
|
-
|
477
|
-
timersub(t1,t2,&diff);
|
478
|
-
|
479
|
-
^
|
480
|
-
|
481
|
-
07_05.c:6:2: warning: implicit declaration of function ‘printf’ [-Wimplicit-function-declaration]
|
482
|
-
|
483
|
-
printf("%02lu:%2lu.%02lu\n",
|
484
|
-
|
485
|
-
^
|
486
|
-
|
487
|
-
07_05.c:6:2: warning: incompatible implicit declaration of built-in function ‘printf’
|
488
|
-
|
489
|
-
07_05.c:6:2: note: include ‘<stdio.h>’ or provide a declaration of ‘printf’
|
490
|
-
|
491
|
-
main.c: In function ‘main’:
|
492
|
-
|
493
|
-
main.c:23:7: warning: implicit declaration of function ‘initTime’ [-Wimplicit-function-declaration]
|
494
|
-
|
495
|
-
if(initTime(&startTime)<0)
|
496
|
-
|
497
|
-
^
|
498
340
|
|
499
341
|
$
|
500
342
|
|
1
コードを伝える。
test
CHANGED
File without changes
|
test
CHANGED
@@ -37,3 +37,465 @@
|
|
37
37
|
Ubuntu 15.10を使用しています。
|
38
38
|
|
39
39
|
よろしくお願いします。
|
40
|
+
|
41
|
+
---
|
42
|
+
|
43
|
+
追記
|
44
|
+
|
45
|
+
本から写したものです。打ち間違いがあるかもしれません。
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
07_01.c
|
50
|
+
|
51
|
+
```#include <sys/time.h>
|
52
|
+
|
53
|
+
#define DATA_FILENAME "./stopwatch.dat"
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
int iniTime(struct timeval *startTime)
|
58
|
+
|
59
|
+
{
|
60
|
+
|
61
|
+
int fd,ret=0;
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
gettimeofday(startTime,NULL);
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
if((fd=open(DATA_FILENAME,O_WRONLY|O_CREAT|O_TRUNC,0644))<0)
|
70
|
+
|
71
|
+
return -1;
|
72
|
+
|
73
|
+
if(Write(fd,startTime,sizeof(*startTime))!=sizeof(*startTime))
|
74
|
+
|
75
|
+
ret=-1;
|
76
|
+
|
77
|
+
close(fd);
|
78
|
+
|
79
|
+
return ret;
|
80
|
+
|
81
|
+
}
|
82
|
+
|
83
|
+
```
|
84
|
+
|
85
|
+
---
|
86
|
+
|
87
|
+
07_02.c
|
88
|
+
|
89
|
+
```
|
90
|
+
|
91
|
+
int restoreTime(struct timeval *startTime)
|
92
|
+
|
93
|
+
{
|
94
|
+
|
95
|
+
int fs,ret=0;
|
96
|
+
|
97
|
+
if((fd=open(DATA_FILENAME,O_RDONLY))<0)
|
98
|
+
|
99
|
+
return -1;
|
100
|
+
|
101
|
+
if(read(fd,strtTime,sizeof(*startTime))!=sizeof(*startTime))
|
102
|
+
|
103
|
+
ret =-1;
|
104
|
+
|
105
|
+
close(fd);
|
106
|
+
|
107
|
+
return ret;
|
108
|
+
|
109
|
+
}
|
110
|
+
|
111
|
+
```
|
112
|
+
|
113
|
+
---
|
114
|
+
|
115
|
+
07_04.c
|
116
|
+
|
117
|
+
```
|
118
|
+
|
119
|
+
void lastTime(int unused)
|
120
|
+
|
121
|
+
{
|
122
|
+
|
123
|
+
struct timeval startTime,lastTime;
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
if(restoreTime(&startTime)<0)
|
128
|
+
|
129
|
+
exit(EXIT_FAILRE);
|
130
|
+
|
131
|
+
gettimeofday(&lastTime,NULL);
|
132
|
+
|
133
|
+
printDiff(&lastTime,&startTime);
|
134
|
+
|
135
|
+
exit(EXIT_SUCCESS);
|
136
|
+
|
137
|
+
}
|
138
|
+
|
139
|
+
```
|
140
|
+
|
141
|
+
---
|
142
|
+
|
143
|
+
07_05.c
|
144
|
+
|
145
|
+
```
|
146
|
+
|
147
|
+
void printDiff(struct timeval *t1,struct timeval *t2)
|
148
|
+
|
149
|
+
{
|
150
|
+
|
151
|
+
struct timeval diff;
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
timersub(t1,t2,&diff);
|
156
|
+
|
157
|
+
printf("%02lu:%2lu.%02lu\n",
|
158
|
+
|
159
|
+
diff.tv_sec/60,
|
160
|
+
|
161
|
+
diff.tv_sec%60,
|
162
|
+
|
163
|
+
diff.tv_usec/10000);
|
164
|
+
|
165
|
+
}
|
166
|
+
|
167
|
+
```
|
168
|
+
|
169
|
+
---
|
170
|
+
|
171
|
+
main.c
|
172
|
+
|
173
|
+
```#include <stdio.h>
|
174
|
+
|
175
|
+
#include <stdlib.h>
|
176
|
+
|
177
|
+
#include <unistd.h>
|
178
|
+
|
179
|
+
#include <sys/time.h>
|
180
|
+
|
181
|
+
#include <fcntl.h>
|
182
|
+
|
183
|
+
#include <signal.h>
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
int iniTime(struct timeval *startTime);
|
188
|
+
|
189
|
+
int restoreTime(struct timeval *startTime);
|
190
|
+
|
191
|
+
void lastTime(int unused);
|
192
|
+
|
193
|
+
void printDiff(struct timeval *t1,struct timeval *t2);
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
int main(int argc,char *argv[])
|
198
|
+
|
199
|
+
{
|
200
|
+
|
201
|
+
int c;
|
202
|
+
|
203
|
+
struct timeval startTime={0,0},currentTime;
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
while((c=getopt(argc,argv,"cs"))!=EOF)
|
208
|
+
|
209
|
+
{
|
210
|
+
|
211
|
+
switch(c)
|
212
|
+
|
213
|
+
{
|
214
|
+
|
215
|
+
case 's':
|
216
|
+
|
217
|
+
if(initTime(&startTime)<0)
|
218
|
+
|
219
|
+
{
|
220
|
+
|
221
|
+
fprintf(stderr,"開始時刻の初期化、書き込みに失敗\n");
|
222
|
+
|
223
|
+
exit(EXIT_FAILURE);
|
224
|
+
|
225
|
+
}
|
226
|
+
|
227
|
+
break;
|
228
|
+
|
229
|
+
case 'c':
|
230
|
+
|
231
|
+
if(restoreTime(&startTime)<0)
|
232
|
+
|
233
|
+
{
|
234
|
+
|
235
|
+
fprintf(stderr,"開始時刻の読み込みに失敗\n");
|
236
|
+
|
237
|
+
exit(EXIT_FAILURE);
|
238
|
+
|
239
|
+
}
|
240
|
+
|
241
|
+
break;
|
242
|
+
|
243
|
+
}
|
244
|
+
|
245
|
+
}
|
246
|
+
|
247
|
+
if(startTime.tv_sec==0||argc!=2)
|
248
|
+
|
249
|
+
{
|
250
|
+
|
251
|
+
fprintf(stderr,"-sまたは-cオプションを指定してください。\n");
|
252
|
+
|
253
|
+
exit(EXIT_FAILURE);
|
254
|
+
|
255
|
+
}
|
256
|
+
|
257
|
+
signal(SIGINT,lastTime);
|
258
|
+
|
259
|
+
while(1)
|
260
|
+
|
261
|
+
{
|
262
|
+
|
263
|
+
sleep(1);
|
264
|
+
|
265
|
+
gettimeofday(¤tTime,NULL);
|
266
|
+
|
267
|
+
printDiff(¤tTime,&startTime);
|
268
|
+
|
269
|
+
}
|
270
|
+
|
271
|
+
exit(EXIT_SUCCESS);
|
272
|
+
|
273
|
+
}
|
274
|
+
|
275
|
+
```
|
276
|
+
|
277
|
+
ターミナルでコンパイルすると、
|
278
|
+
|
279
|
+
```
|
280
|
+
|
281
|
+
$ gcc 07_01.c 07_02.c 07_04.c 07_05.c main.c
|
282
|
+
|
283
|
+
07_01.c: In function ‘iniTime’:
|
284
|
+
|
285
|
+
07_01.c:8:25: error: ‘NULL’ undeclared (first use in this function)
|
286
|
+
|
287
|
+
gettimeofday(startTime,NULL);
|
288
|
+
|
289
|
+
^
|
290
|
+
|
291
|
+
07_01.c:8:25: note: each undeclared identifier is reported only once for each function it appears in
|
292
|
+
|
293
|
+
07_01.c:10:9: warning: implicit declaration of function ‘open’ [-Wimplicit-function-declaration]
|
294
|
+
|
295
|
+
if((fd=open(DATA_FILENAME,O_WRONLY|O_CREAT|O_TRUNC,0644))<0)
|
296
|
+
|
297
|
+
^
|
298
|
+
|
299
|
+
07_01.c:10:28: error: ‘O_WRONLY’ undeclared (first use in this function)
|
300
|
+
|
301
|
+
if((fd=open(DATA_FILENAME,O_WRONLY|O_CREAT|O_TRUNC,0644))<0)
|
302
|
+
|
303
|
+
^
|
304
|
+
|
305
|
+
07_01.c:10:37: error: ‘O_CREAT’ undeclared (first use in this function)
|
306
|
+
|
307
|
+
if((fd=open(DATA_FILENAME,O_WRONLY|O_CREAT|O_TRUNC,0644))<0)
|
308
|
+
|
309
|
+
^
|
310
|
+
|
311
|
+
07_01.c:10:45: error: ‘O_TRUNC’ undeclared (first use in this function)
|
312
|
+
|
313
|
+
if((fd=open(DATA_FILENAME,O_WRONLY|O_CREAT|O_TRUNC,0644))<0)
|
314
|
+
|
315
|
+
^
|
316
|
+
|
317
|
+
07_01.c:12:5: warning: implicit declaration of function ‘Write’ [-Wimplicit-function-declaration]
|
318
|
+
|
319
|
+
if(Write(fd,startTime,sizeof(*startTime))!=sizeof(*startTime))
|
320
|
+
|
321
|
+
^
|
322
|
+
|
323
|
+
07_01.c:14:2: warning: implicit declaration of function ‘close’ [-Wimplicit-function-declaration]
|
324
|
+
|
325
|
+
close(fd);
|
326
|
+
|
327
|
+
^
|
328
|
+
|
329
|
+
07_02.c:1:24: warning: ‘struct timeval’ declared inside parameter list
|
330
|
+
|
331
|
+
int restoreTime(struct timeval *startTime)
|
332
|
+
|
333
|
+
^
|
334
|
+
|
335
|
+
07_02.c:1:24: warning: its scope is only this definition or declaration, which is probably not what you want
|
336
|
+
|
337
|
+
07_02.c: In function ‘restoreTime’:
|
338
|
+
|
339
|
+
07_02.c:4:6: error: ‘fd’ undeclared (first use in this function)
|
340
|
+
|
341
|
+
if((fd=open(DATA_FILENAME,O_RDONLY))<0)
|
342
|
+
|
343
|
+
^
|
344
|
+
|
345
|
+
07_02.c:4:6: note: each undeclared identifier is reported only once for each function it appears in
|
346
|
+
|
347
|
+
07_02.c:4:9: warning: implicit declaration of function ‘open’ [-Wimplicit-function-declaration]
|
348
|
+
|
349
|
+
if((fd=open(DATA_FILENAME,O_RDONLY))<0)
|
350
|
+
|
351
|
+
^
|
352
|
+
|
353
|
+
07_02.c:4:14: error: ‘DATA_FILENAME’ undeclared (first use in this function)
|
354
|
+
|
355
|
+
if((fd=open(DATA_FILENAME,O_RDONLY))<0)
|
356
|
+
|
357
|
+
^
|
358
|
+
|
359
|
+
07_02.c:4:28: error: ‘O_RDONLY’ undeclared (first use in this function)
|
360
|
+
|
361
|
+
if((fd=open(DATA_FILENAME,O_RDONLY))<0)
|
362
|
+
|
363
|
+
^
|
364
|
+
|
365
|
+
07_02.c:6:5: warning: implicit declaration of function ‘read’ [-Wimplicit-function-declaration]
|
366
|
+
|
367
|
+
if(read(fd,strtTime,sizeof(*startTime))!=sizeof(*startTime))
|
368
|
+
|
369
|
+
^
|
370
|
+
|
371
|
+
07_02.c:6:13: error: ‘strtTime’ undeclared (first use in this function)
|
372
|
+
|
373
|
+
if(read(fd,strtTime,sizeof(*startTime))!=sizeof(*startTime))
|
374
|
+
|
375
|
+
^
|
376
|
+
|
377
|
+
07_02.c:6:29: error: dereferencing pointer to incomplete type ‘struct timeval’
|
378
|
+
|
379
|
+
if(read(fd,strtTime,sizeof(*startTime))!=sizeof(*startTime))
|
380
|
+
|
381
|
+
^
|
382
|
+
|
383
|
+
07_02.c:8:2: warning: implicit declaration of function ‘close’ [-Wimplicit-function-declaration]
|
384
|
+
|
385
|
+
close(fd);
|
386
|
+
|
387
|
+
^
|
388
|
+
|
389
|
+
07_04.c: In function ‘lastTime’:
|
390
|
+
|
391
|
+
07_04.c:3:17: error: storage size of ‘startTime’ isn’t known
|
392
|
+
|
393
|
+
struct timeval startTime,lastTime;
|
394
|
+
|
395
|
+
^
|
396
|
+
|
397
|
+
07_04.c:3:27: error: storage size of ‘lastTime’ isn’t known
|
398
|
+
|
399
|
+
struct timeval startTime,lastTime;
|
400
|
+
|
401
|
+
^
|
402
|
+
|
403
|
+
07_04.c:5:5: warning: implicit declaration of function ‘restoreTime’ [-Wimplicit-function-declaration]
|
404
|
+
|
405
|
+
if(restoreTime(&startTime)<0)
|
406
|
+
|
407
|
+
^
|
408
|
+
|
409
|
+
07_04.c:6:3: warning: implicit declaration of function ‘exit’ [-Wimplicit-function-declaration]
|
410
|
+
|
411
|
+
exit(EXIT_FAILRE);
|
412
|
+
|
413
|
+
^
|
414
|
+
|
415
|
+
07_04.c:6:3: warning: incompatible implicit declaration of built-in function ‘exit’
|
416
|
+
|
417
|
+
07_04.c:6:3: note: include ‘<stdlib.h>’ or provide a declaration of ‘exit’
|
418
|
+
|
419
|
+
07_04.c:6:8: error: ‘EXIT_FAILRE’ undeclared (first use in this function)
|
420
|
+
|
421
|
+
exit(EXIT_FAILRE);
|
422
|
+
|
423
|
+
^
|
424
|
+
|
425
|
+
07_04.c:6:8: note: each undeclared identifier is reported only once for each function it appears in
|
426
|
+
|
427
|
+
07_04.c:7:2: warning: implicit declaration of function ‘gettimeofday’ [-Wimplicit-function-declaration]
|
428
|
+
|
429
|
+
gettimeofday(&lastTime,NULL);
|
430
|
+
|
431
|
+
^
|
432
|
+
|
433
|
+
07_04.c:7:25: error: ‘NULL’ undeclared (first use in this function)
|
434
|
+
|
435
|
+
gettimeofday(&lastTime,NULL);
|
436
|
+
|
437
|
+
^
|
438
|
+
|
439
|
+
07_04.c:8:2: warning: implicit declaration of function ‘printDiff’ [-Wimplicit-function-declaration]
|
440
|
+
|
441
|
+
printDiff(&lastTime,&startTime);
|
442
|
+
|
443
|
+
^
|
444
|
+
|
445
|
+
07_04.c:9:2: warning: incompatible implicit declaration of built-in function ‘exit’
|
446
|
+
|
447
|
+
exit(EXIT_SUCCESS);
|
448
|
+
|
449
|
+
^
|
450
|
+
|
451
|
+
07_04.c:9:2: note: include ‘<stdlib.h>’ or provide a declaration of ‘exit’
|
452
|
+
|
453
|
+
07_04.c:9:7: error: ‘EXIT_SUCCESS’ undeclared (first use in this function)
|
454
|
+
|
455
|
+
exit(EXIT_SUCCESS);
|
456
|
+
|
457
|
+
^
|
458
|
+
|
459
|
+
07_05.c:1:42: warning: ‘struct timeval’ declared inside parameter list
|
460
|
+
|
461
|
+
void printDiff(struct timeval *t1,struct timeval *t2)
|
462
|
+
|
463
|
+
^
|
464
|
+
|
465
|
+
07_05.c:1:42: warning: its scope is only this definition or declaration, which is probably not what you want
|
466
|
+
|
467
|
+
07_05.c: In function ‘printDiff’:
|
468
|
+
|
469
|
+
07_05.c:3:17: error: storage size of ‘diff’ isn’t known
|
470
|
+
|
471
|
+
struct timeval diff;
|
472
|
+
|
473
|
+
^
|
474
|
+
|
475
|
+
07_05.c:5:2: warning: implicit declaration of function ‘timersub’ [-Wimplicit-function-declaration]
|
476
|
+
|
477
|
+
timersub(t1,t2,&diff);
|
478
|
+
|
479
|
+
^
|
480
|
+
|
481
|
+
07_05.c:6:2: warning: implicit declaration of function ‘printf’ [-Wimplicit-function-declaration]
|
482
|
+
|
483
|
+
printf("%02lu:%2lu.%02lu\n",
|
484
|
+
|
485
|
+
^
|
486
|
+
|
487
|
+
07_05.c:6:2: warning: incompatible implicit declaration of built-in function ‘printf’
|
488
|
+
|
489
|
+
07_05.c:6:2: note: include ‘<stdio.h>’ or provide a declaration of ‘printf’
|
490
|
+
|
491
|
+
main.c: In function ‘main’:
|
492
|
+
|
493
|
+
main.c:23:7: warning: implicit declaration of function ‘initTime’ [-Wimplicit-function-declaration]
|
494
|
+
|
495
|
+
if(initTime(&startTime)<0)
|
496
|
+
|
497
|
+
^
|
498
|
+
|
499
|
+
$
|
500
|
+
|
501
|
+
```
|