
z_
Core Language Module with datatypes, memory tracker, and _more_.About
This library provides Core Functionality built upon the C language. Inspired and taken from Modern Languages such as Python, Rust etc.
- Memory Management: Allocators, Memory Debugger.
- Types & Data Structures: Clean Systematic Data types and Structures with feature-full fuctionality.
- Meta-Programming: An absolute abuse of C-preprocessor.
- Utilities: Mini Libraries and modules for extendend fucntionality (e.g. TUI) and wrappers (e.g. curl, cglm)
Sub-Modules
List of sub-modules of provided by the library.
- ansifmt.h: ANSI Terminal string format (e.g. clear, jump cursor, change text color)
- argparse.h: Parse list of arguments of a program.
- arr.h: Implementation of Generic Dyanmic Array
- arrfree.h: Implementation of auto free for Dyanmic array type
- arrllist.h: Implementation of Array Allocated Generic Linked List
- assert.h: Custom assert implementation.
- atomic.h: Custom atomic wrapper.
- autotype.h: Autotype alias.
- bitf.h: Macros for bit field manupilation
- bnf.h: Context free grammer notation Backus-Naur form
- bytes.h: Implementation of byte array
- cglm.h: Wrapper for cglm
- contof.h: Container of macro
- curl.h: Wrapper around curl
- dynt.h: Implementation of Opaque Array
- enum.h: Implementation of Sum Type
- fio.h: File IO
- fnptr.h: Function pointer macro
- forrange.h: For-range for different data types
- gmath.h: Math functions for vectors and matrix
- hashset.h: Implementation of Generic Hash List/Map/Table
- hashstr.h: Implementation of String Key, Hash Set.
- htmlfmt.h: Format Macro for html
- irrg.h: Implementation of Opaque List
- lexer.h: Generic Lexer
- llist.h: Implementation of Linked List
- map.h: Multi-layer tilemap.
- map2d.h: Single-layer tilemap.
- map3d.h: 3-Dimentional tilemap.
- mapch.h: Multi Chunk 3D tilemap
- matrix.h: Matrix Type
- obj.h: Closure & V-Tables
- omp.h: OpenMP wrapper
- option.h: Implementation of Option Sum Type
- offsetof.h: Custom Offset macro.
- pairarr.h: Implementation of Pair Array
- print.h: Print Implentation
- record.h: Struct Gen that can be used by c macros, Record.
- result.h: Result Type
- return.h: Function return definitions
- sys.h: Functions for comunicating with system.
- subp.h: Spawing a sub-process/child process
- soarr.h: Implementation of Struct of Arrays
- strto.h:
- serial.h:
- string.h: Implementation of Byte String (ASCII).
- string8.h: Implementation of utf-8 compactible String.
- tui.h: Terminal based UI, lightweight alternative to ncurses.
- time.h: Time based functionality
- test.h: Test Suite Impletation
- tree.h: m-ary tree Implentationw
- type.h: Define a Type Set
- tuple.h: Implementation of Tuple Type.
- termio.h: Terminal io functions
- thread.h: Thread Wrapper around pthread
- typeid.h: List of Type-ids generated from
typegen.h
- typeof.h: typeof macro
- tgprint.h: Type Generic Print
- typegen.h: Macro for generating type info
- utf8.h: utf-8 functions
- u8arr.h: u8 array
- utils.h: Utility macro and functions
- vector.h: Vector Type
Pre-Processing Modules (PreP)
Meta-programming using C-preprocessor. Explore Source
- prep/args.h: Macro for passed-in arguments.
- prep/base.h: Basic Utility Macros
- prep/call.h: Function Call Wrapper
- prep/eval.h: Eval Macro
- prep/loop.h: Macro for compile-time loop
- prep/map.h: Map Macro
-
prep/num.h: Macro for compile time small number arithmatic and comparism
- prep/nm/assert.h: Assert Constructors
- prep/nm/cond.h:
- prep/nm/ident.h:
- prep/nm/pragma.h:
- prep/nm/string.h:
Helper function for preprocessor macros, not used directly
- prep/gen/args/applyfxy.h
- prep/gen/args/get.h
- prep/gen/args/getupto.h
- prep/gen/args/skip.h
- prep/gen/num/dec_u8.h
- prep/gen/num/dec_n1024.h
- prep/gen/num/dec_n2048.h
- prep/gen/num/inc_u8.h
- prep/gen/num/inc_n1024.h
- prep/gen/num/inc_n2048.h
Prelude
Stuff that is probably needed everywhere.
- std/alloc.h: Alloctor
- std/arch.h: Macro for defining Architecture
- std/io.h: IO Functions
- std/mem.h: Memory Function
- std/primitives.h: Primitives
Getting Started
z_
is made with modularity in mind so many parts of it are as self-isolated as they can,
it doesn’t even include standard library except stddef.h
, stdint.h
and stdbool.h
for type
declaration but they still require the bare minimum base
for to be working properly such
as, z_/arr.h
can be included in itself but it still require base.h
of types
for z__u32
and mem.h
for memory allocation definitions.
Therefore, You need to explicitly include the <stdlib.h>
, <string.h>
.
Installing
Method 1: Local Integration
Inorder to integrated z_
in your project only
git clone --depth=1 git://github.com/zakarouf/z_.git
sh build.sh lib
Will result a library libz_.a created in the ./build/lib
and headers at ./build/include
as z_
directory.
Copy the z_
folder onto your include
directory. And copy the libz_.a
to the lib
directory and link it against the executable and we are good to go.
#include <z_/z_.h>
Method 2: Global Installation
Run the build.sh
script, with the following parameters
sh build.sh install lib
By Default, the path for Headers is usr/local/include/z_
and for library it is libz_.a
, you can change it by editing the
build.sh
file itself, LIB_DIR
and INCLUDE_DIR
to be specfic.
Config
Inside the source directory config_{MODULE}.h
that can be modified by the user in-order to change the behaviour, include, exclude the fuctionality of that sub-library.
{MODULE} is the name of the Module i.e. config_imp.h, config_prep.h etc.
Such as inside of src/lib/_config_types.h
#define Z___TYPE_CONFIG__USE_TYPE_LINKEDLIST
This particular config tells to include the Linked List type and its functionaity at core; when
z_.h
is included, and if we comment out it
//#define Z___TYPE_CONFIG__USE_TYPE_LINKEDLIST
Will result in a error This forces to you to include linked list type manually.
#include <z_/types/llist.h>
Now this will work as it should.
Using Library
z_
is now uses stb-style header impletation macro without compiling a .a
library to link to.
Define Z__IMPLEMENTATION
in any one of the source file before including the header.
I would recommended creating a seperate empty source file with all the impletation defined.
#define Z__IMPLEMENTATION
#include <z_/time.h>
Adding Syntax Highlighting (Vim & NeoVim)
Additional syntax Highlighting for types and such are include in the extra/c.vim.
To add it into your project, either copy the contents of the c.vim
file or put
c.vim
into your after/syntax
folder, such as ~/.config/vim/after/syntax/
directory.
This will load on top of your syntax highlighting for every .c file.
Documentation
FAQs
Why did I create this library? || History behind z_.
z_
had a humble beginning as a single header for defining primitive types in ztorg project.
Later on I added more quality of life stuff such as Type-Generic Dyanmic Arrays etc. It was then I decided to move its development to a separate repo with more than just a “Data Type Library”. I wanted to created a core, standard-library that I can just use anywhere as a starting point.
Os & Compiler Support?
Linux and MacOS is fully supported while, with Windows your mileage might vary.
As for Compiler GCC or Clang is recommended.
Why heavy use of macros?
Bloat. Creating such library that I can use anywhere, I wanted to have as less bloated binary wise as posible, while also having to combat the non-type generic nature of the C language.
If by any case, I dont want use a bare macro. I would wrap it up inside of a function.
#define my_macro_function(a, b) { ... }
void my_function(int a, int b)
{
my_macro_function(a, b);
}
Who is this for?
Me. Or you if you stumble upon my stuff and found it cool. But as of writing, I created this for myself. This repo is so I can easily maintain and access the code and or share it with my friends. I am not a good Programmer by a long shot, I just like when my computer goes beep-boop.
Credit & References
It takes many features from other libraries and projects. Whilst also some Reffrences and books.
Types
Sum Types :: z__Enum
Hirrolot’s Datatype99. For my own implementation of Sum Types. The actual impletation is dis-similar to them. My implementation of z__Enum is no where near as elegant as Datatype99.
Misc
Awesome C Preprocessor Helped to study on the C’s magical Preprocessor.
Previews & Example






See Also
Ending Note
This library is not perfect and I know there are many others like it, but this one is mine <3.