Skip to content

Latest commit

 

History

History
71 lines (47 loc) · 1.37 KB

File metadata and controls

71 lines (47 loc) · 1.37 KB

Examples

This folder contains example usage for both C and C++.

How to Compile

Because zvec uses macro generation to create type-safe containers, there is a one-time setup step to register your types.

  1. Inside include/ either make your own registry header (like my_vectors.h or something similar), or use zscanner.py.

  2. If you use the scanner, remember you can get it with:

git submodule update --init --recursive

Then just do:

python3 ../z-core/zscanner.py c/ include/z_registry.h

Note: If you are compiling the C++ examples change c/ to cpp/

Expect an output like this:

Scanning c/...
Generating include/z_registry.h...
Done.

z_registry.h should look similar to this:

/* AUTO-GENERATED BY Z-SCANNER - DO NOT EDIT */
#ifndef Z_REGISTRY_H
#define Z_REGISTRY_H

/* Vectors */
#define Z_AUTOGEN_VECS(X) \
    X(int, Int) \
    X(Point, Point) \

/* Lists */
#define Z_AUTOGEN_LISTS(X) \

/* Maps */
#define Z_AUTOGEN_MAPS(X) \

#endif // Z_REGISTRY_H
  1. To compile then you can simply do:

For C:

gcc c/example_0.c -I.. -Iinclude -o example_c
./example_c

For C++:

g++ cpp/example_0.cpp -I.. -Iinclude -o example_cpp
./example_cpp

-I.. is needed to include zvec.h. You can simply just move it, but this way we keep the current structure. -Iinclude includes the registry header.