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
#include <stdio.h>

#include "vector.h"

void
VectorPrint(const struct Vector *vec)
{
    for (size_t i = 0; i < vec->dim; ++i) {
        printf("%lf", VectorElement(vec, i));
        if (i + 1 < vec->dim) {
            printf(", ");
        }
    }
}

int
main(void)
{
    // define and construct vector
    struct Vector x = VectorConstruct(4);

    for (size_t i = 0; i < x.dim; ++i) {
        *VectorElementPtr(&x, i) = 42 + i;
    }

    VectorPrint(&x);
    printf("\n");

    // destruct vector before it leaves scope
    VectorDestruct(&x);
}