Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

An Easy-to-use Framework for the C Language.

License

NotificationsYou must be signed in to change notification settings

zakarouf/z_

Repository files navigation

z_

Core Language Module with datatypes, memory tracker, andmore.

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.

Sub-moduleDescription
ansifmt.hANSI Terminal string format (e.g. clear, jump cursor, change text color)
argparse.hParse list of arguments of a program.
arr.hImplementation of Generic Dyanmic Array
arrfree.hImplementation of auto free for Dyanmic array type
arrllist.hImplementation of Array Allocated Generic Linked List
assert.hCustom assert implementation.
atomic.hCustom atomic wrapper.
autotype.hAutotype alias.
bitf.hMacros for bit field manupilation
bnf.hContext free grammer notationBackus-Naur form
bytes.hImplementation of byte array
cglm.hWrapper for cglm
contof.hContainer of macro
curl.hWrapper around curl
dynt.hImplementation of Opaque Array
enum.hImplementation ofSum Type
fio.hFile IO
fnptr.hFunction pointer macro
forrange.hFor-range for different data types
gmath.hMath functions for vectors and matrix
hashset.hImplementation of Generic Hash List/Map/Table
hashstr.hImplementation of String Key, Hash Set.
htmlfmt.hFormat Macro for html
irrg.hImplementation of Opaque List
lexer.hGeneric Lexer
llist.hImplementation ofLinked List
map.hMulti-layer tilemap.
map2d.hSingle-layer tilemap.
map3d.h3-Dimentional tilemap.
mapch.hMulti Chunk 3D tilemap
matrix.hMatrix Type
obj.hClosure & V-Tables
omp.hOpenMP wrapper
option.hImplementation of Option Sum Type
offsetof.hCustom Offset macro.
pairarr.hImplementation of Pair Array
print.hPrint Implentation
record.hStruct Gen that can be used by c macros,Record.
result.hResult Type
return.hFunction return definitions
random.hPRNG & Hash Functions
sys.hFunctions for comunicating with system.
subp.hSpawing a sub-process/child process
soarr.hImplementation of Struct of Arrays
strto.hDo a type generic sscanf
serial.hSerializer
string.hImplementation of Byte String (ASCII).
string8.hImplementation of utf-8 compactible String.
tui.hTerminal based UI, lightweight alternative to ncurses.
time.hTime based functionality
test.hTest Suite Impletation
tree.hm-ary tree Implentation
type.hDefine a Type Set
tuple.hImplementation ofTuple Type.
termio.hTerminal io functions
thread.hThread Wrapper around pthread
typeid.hList of Type-ids generated fromtypegen.h
typeof.htypeof macro
tgprint.hType Generic Print
typegen.hMacro for generating type info
utf8.hutf-8 functions
u8arr.hu8 array
utils.hUtility macro and functions
vector.hVector Type

Pre-Processing Modules (PreP)

Meta-programming using C-preprocessor.Explore Source

Sub-ModuleDescription
prep/args.hMacro for passed-in arguments.
prep/base.hBasic Utility Macros
prep/call.hFunction Call Wrapper
prep/eval.hEval Macro
prep/loop.hMacro for compile-time loop
prep/map.hMap Macro
prep/num.hMacro for compile time small number arithmatic and comparism
prep/nm/assert.hAssert 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

NameDescription
prep/comp/eval.h
prep/gen/args/applyfxy.h
prep/gen/args/get.h
prep/gen/args/getupto.h
prep/gen/args/skip.h
prep/gen/args/var.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.

Sub-ModuleDescription
std/alloc.hAllocator
std/arch.hMacro for defining Architecture
std/io.hIO Functions
std/mem.hMemory Function
std/primitives.hPrimitives

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 exceptstddef.h,stdint.h andstdbool.h for typedeclarationbut they still require the bare minimumbase for to be working properly suchas,z_/arr.h can be included in itself but it still requirebase.h oftypesforz__u32 andmem.h for memory allocation definitions.

Therefore, You need to explicitly include the<stdlib.h>,<string.h>.

Installing

Method 1: Local Integration

Inorder to integratedz_ in your project only

git clone --depth=1 git://github.com/zakarouf/z_.gitsh build.sh lib

Will result a library libz_.a created in the./build/lib and headers at./build/include asz_ directory.

Copy thez_ folder onto yourinclude directory. And copy thelibz_.a to thelib directory and link it against the executable and we are good to go.

#include<z_/z_.h>

Method 2: Global Installation

Run thebuild.sh script, with the following parameters

sh build.sh install lib

By Default, the path for Headers isusr/local/include/z_ and for library it islibz_.a, you can change it by editing thebuild.sh file itself,LIB_DIR andINCLUDE_DIR to be specfic.

Config

Inside the source directoryconfig_{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 ofsrc/lib/_config_types.h

#defineZ___TYPE_CONFIG__USE_TYPE_LINKEDLIST

This particular config tells to include the Linked List type and its functionaity at core; whenz_.h is included, and if we comment out it

//#define Z___TYPE_CONFIG__USE_TYPE_LINKEDLIST

error1

Will result in a errorThis 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.DefineZ__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.

#defineZ__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 thec.vim file or putc.vim into yourafter/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 inztorg 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.

#definemy_macro_function(a,b) { ... }voidmy_function(inta,intb){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'sDatatype99. For my own implementation of Sum Types. The actual impletation is dis-similar to them. My implementation ofz__Enum is no where near as elegant as Datatype99.

Misc

Awesome C Preprocessor Helped to study on the C's magical Preprocessor.

Previews & Example

Sum of an Integer Array
Intializing an Array of Functions in a single line
Sum of Binary tree using Enum
Web Event with Enums
Fill Up an array of Vector2 with OpenMP
Creating a Map with Pthread

See Also


Ending Note

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



[8]ページ先頭

©2009-2025 Movatter.jp