-
Notifications
You must be signed in to change notification settings - Fork 0
/
c_getc.c
98 lines (46 loc) · 1.25 KB
/
c_getc.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
69
70
71
72
73
74
75
76
77
////////////////////////////////////////////////////////////////////////////////
#include <stdio.h>
//
void c_getc_ ( FILE **fp, int *c )
{
*c = getc ( *fp );
}
//
//
// New version:
// Pass arguments using its reference with value in integer(8), i.e.
// intptr_t defined in /usr/include/stdint.h
//
#include <stdint.h>
void c_getc_intref_ ( intptr_t *iptr, int *c )
{
// Should we cast the types in every byte? Consider!
*c = getc ( (FILE *) (*iptr) );
}
/*
DEPRECATED.
Or, consider this procedure:
Use global variable for casting types only one time
because casting types may cost time!
We use registry list of pointers.
--> NO IT'S EXTREMELY FAST! I CHECKED.
//const int MAX_IPTRLIST = 50 ;
#define MAX_IPTRLIST 50
FILE *IPTRLIST_fgetc[MAX_IPTRLIST] = {NULL} ;
// Make sure 0 <= *id <= 49
// pre-processing: do this only only one time for every stream
void c_fgetc_intref_pre_ ( int *id, intptr_t *iptr )
{
IPTRLIST_fgetc[*id] = (FILE *) (*iptr) ;
}
// processing:
void c_fgetc_intref_pro_ ( int *id, int *c )
{
*c = fgetc ( IPTRLIST_fgetc[*id] );
}
// end-processing:
void c_fgetc_intref_end_ ( int *id )
{
IPTRLIST_fgetc[*id] = NULL ;
}
*/