-
Notifications
You must be signed in to change notification settings - Fork 0
/
ex7_vector.h
55 lines (47 loc) · 1.9 KB
/
ex7_vector.h
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
#ifndef CS61C_VECTOR_H_
#define CS61C_VECTOR_H_
/* vector.h originally written by Jeremy Huddleston <[email protected]> Sp2004
*
* So it looks like you've decided to venture into the "other" files of this
* lab. Good. C Header files (the .h extension) are a way of telling other .c
* files what they can have access to. You usually include stdlib.h in your
* C programs, and this process is identical to including this .h file with the
* one change being:
*
* #include "file.h"
* versus
* #include <file.h>
*
* The difference is that the <> notation is for system header files and the ""
* is for ones you provide yourself (in your local directory for instance).
*
* The header file starts off with
* #ifndef CS61C_VECTOR_H_
* #define CS61C_VECTOR_H_
*
* and ends with a final #endif. This prevents the file from being included
* more than once which could've possibly resulted in an infinite loop of
* file inclusions.
*
* First, we define the 'vector_t' datatype. This next line says that a 'vector_t'
* is the same as a 'struct vector_t'. So anywhere in the code after this, we
* can use 'vector_t *' to mean a pointer to a 'struct vector_t' (which is defined in
* vector.c). We can get away with doing this even though we don't know what a
* struct vector is because all struct pointers have the same representation in memory.
*/
#include <sys/types.h>
typedef struct vector_t vector_t;
/*
* Next, we provide the prototypes for the functions defined in vector.c. This
* is a way of telling the .c files that #include this header what they will
* have access to.
*/
/* Create a new vector */
vector_t *vector_new();
/* Free up the memory allocated for the passed vector */
void vector_delete(vector_t *v);
/* Return the value in the vector */
int vector_get(vector_t *v, size_t loc);
/* Set a value in the vector */
void vector_set(vector_t *v, size_t loc, int value);
#endif