-
Notifications
You must be signed in to change notification settings - Fork 0
/
basic.c
69 lines (58 loc) · 1.37 KB
/
basic.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
* File: basic.c
* - error handler
* - memory management
* - ...
*
* Author: Hermann Stamm-Wilbrandt
* Institut fuer Informatik III
* Roemerstr. 164
* Bonn University
* D-53117 Bonn
* Germany
* email: hermann@holmium.informatik.uni-bonn.de
* phone: 0228-550-260 internal: x260 or x28, Fax: 0228-550-382
*
* For my safety:
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
#include "basic.h"
void err_handler(int no,char *mesg)
{
(void) fprintf(stderr,"[%d] %s\n",no,mesg);
if (no!=0)
exit(no);
}
static int _malloc=0;
static int _free=0;
void *MALLOC(size_t n)
{
void *p = malloc(n);
_malloc++;
return p;
}
void FREE(void *p)
{
(void) free(p);
_free++;
}
void statistics()
{
(void) fprintf(stderr,"\n");
(void) fprintf(stderr,"-------------------------------------\n");
(void) fprintf(stderr,"malloc: %d malloc-free: %d\n",_malloc,_malloc-_free);
}
num MIN(num x, num y) { return (x<y) ? x : y; }
num MAX(num x, num y) { return (x>y) ? x : y; }
void SWAP(num *a, num *b) { num h=*a; *a=*b; *b=h; }
void USE1()
{
(void) MALLOC(MIN(0,1)+MAX(2,3));
FREE(0);
statistics();
err_handler(7,"da");
USE1();
}