{"id":47597454,"url":"https://github.com/whatchamacallem/libhatchet","last_synced_at":"2026-05-11T01:29:17.379Z","repository":{"id":345451036,"uuid":"1185898207","full_name":"whatchamacallem/libhatchet","owner":"whatchamacallem","description":"libhatchet is a lightweight C17/C++20 bespoke alternative to the C++ standard library designed for cross-compilation to resource-constrained targets like DSPs, FPGAs, ASICs or WebAssembly. ","archived":false,"fork":false,"pushed_at":"2026-04-02T05:54:53.000Z","size":1239,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-04-02T07:38:11.492Z","etag":null,"topics":["asic","c-plus-plus-20","c-plus-plus-programming","cross-compile","dsp","embedded","embedded-systems","fpga","google-test","wasm","webassembly"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/whatchamacallem.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-03-19T03:43:42.000Z","updated_at":"2026-03-30T23:06:17.000Z","dependencies_parsed_at":null,"dependency_job_id":"8dbad0f2-ad46-4430-940c-e3ae2f25867f","html_url":"https://github.com/whatchamacallem/libhatchet","commit_stats":null,"previous_names":["whatchamacallem/libhatchet"],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/whatchamacallem/libhatchet","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/whatchamacallem%2Flibhatchet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/whatchamacallem%2Flibhatchet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/whatchamacallem%2Flibhatchet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/whatchamacallem%2Flibhatchet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/whatchamacallem","download_url":"https://codeload.github.com/whatchamacallem/libhatchet/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/whatchamacallem%2Flibhatchet/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31702581,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-11T21:17:31.016Z","status":"online","status_checked_at":"2026-04-12T02:00:06.763Z","response_time":58,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["asic","c-plus-plus-20","c-plus-plus-programming","cross-compile","dsp","embedded","embedded-systems","fpga","google-test","wasm","webassembly"],"created_at":"2026-04-01T18:24:15.585Z","updated_at":"2026-05-11T01:29:17.362Z","avatar_url":"https://github.com/whatchamacallem.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# libhatchet\n\nPlease use the most recent tagged release.\n\n## Overview\n\n\u003e People say that you should not micro-optimize. But if what you love is\n\u003e micro-optimization... that's what you should do. — Linus Torvalds\n\nlibhatchet is a lightweight, bespoke C17/C++23 alternative to the C++ standard\nlibrary designed for cross-compilation to resource-constrained targets like\nDSPs, FPGAs, ASICs or WebAssembly. It also falls back to requiring only C99\nlibraries and a C++11 compiler, and deliberately avoids dependencies on the C++\nstandard library. For those with a low-level mindset, the developer experience\nis better than with the C++ standard library. For example, the template\ninstantiation errors are easier to read, and `hxassertmsg` will format your\nassert messages before setting a breakpoint for you. There is nothing\nunnecessary to step through in the debugger. Compile times are shockingly fast\nwhen using `ccache` without precompiled headers. The compiler's budget for\noptimization isn't blown out by layers you don't normally need. Although\nintrinsics are available for that problem.\n\n\u003cimg src=\"libhatchet.jpg\" alt=\"banner\" width=\"200\" height=\"200\" align=\"right\" hspace=\"20\"\u003e\n\nA key property of this codebase is its embrace of clang's Undefined Behavior\nSanitizer (UBSan), which enables developers to write pointer-centric C++ code\nwhile enjoying runtime checks comparable to managed languages. The\nimplementation maintains compatibility with all possible warning flags and\nsanitizers for both gcc and clang. Of course, asserts are also widely used. The\nimplementation also avoids dynamic allocations except when initializing system\nallocators.\n\n## Key Features\n\n- **Library hardening and asserts** are controlled via `HX_HARDENING_MODE`.\n\n  E.g. usage is `-DHX_HARDENING_MODE=HX_HARDENING_MODE_NONE`. See `libhatchet.h`\n  for the different kinds of asserts available.\n\n  - `HX_HARDENING_MODE_NONE`: Omits library hardening and disables all asserts.\n  - `HX_HARDENING_MODE_STANDARD`: Provides hardening but saves space by omitting\n    verbose output. Meets the requirements of the C++ standard.\n  - `HX_HARDENING_MODE_VERBOSE`: Provides verbose messages, suitable for\n    internal release. Meets the requirements of the C++ standard.\n  - `HX_HARDENING_MODE_DEBUG`: Provides comprehensive asserts and verbose\n    output.\n\n- **Portability**: Porting to different versions of the C++ standard library are\n  no longer a concern. libhatchet can easily be made to run on top of any old\n  embedded C99 library. musl libc is recommended for embedded Linux and is\n  widely packaged: \u003chttps://musl.libc.org/\u003e. No other C++ runtime or C++ code is\n  required. pthreads or C99's `\u003cthread.h\u003e` may be used for threading, which are\n  widely implemented standards.\n\n- **Profiling System**: Uses processor cycle sampling to create a hierarchical\n  timeline capture compatible with Chrome's `about://tracing` viewer (navigation\n  uses W, A, S, and D keys). One line of assembly may be needed for uncommon\n  hardware.\n\n- **Memory Management**: RAII-based abstraction layer supporting various\n  allocation strategies, particularly valuable for applications where crashing\n  from memory fragmentation is unacceptable. If you have a lot of temporary\n  allocations, this system reasonably offers 30% memory and 30% performance\n  improvements with minor modifications to your code.\n\n- **Console**: Provides an embedded command processor with automatic C++\n  function binding using templates. Useful for interactive target debugging\n  without recompilation and also provides support for config files or\n  configuration via the command-line. Syntax is just `verb [arg ...]`.\n\n- **Testing Framework**: Safer, lighter, debuggable reimplementation of core\n  Google Test functionality.\n\n- **Task Queue**: An unopinionated task queue with priorities and a worker pool.\n  An execution graph is also available as a layer on top.\n\n- **Containers**: Provides a set of containers designed for environments where\n  reallocation is not used. `hxarray` provides a statically or dynamically\n  allocated array. This class was written with an exhaustive feature set because\n  arrays are cache-coherent and memory efficient. E.g. it implements a priority\n  queue as well. `hxhash_table` provides unordered sets and maps without\n  requiring nodes to be subclasses or using copies and allocations. `hxlist`\n  similarly operates without requiring copies or allocations. `hxdeque` provides\n  a highly optimized deque compared to the standard. `hxbitset` is available for\n  bit manipulation. That said, this codebase is intended for low-level work\n  where complex container libraries cause code bloat, memory fragmentation, and\n  poor cache coherence. If those are not your concerns, consider using\n  additional libraries. No Red-Black Tree has been provided.\n\n- **Pretty Printers** Implements GDB-compatible pretty printers, enabling\n  debuggers and most code editors to display container contents in a\n  human-readable format.\n\n- **Algorithms**: `hxradix_sort` is provided for Θ(n) sorting. See\n  `\u003chx/hxalgorithm.h\u003e` for standard algorithms and comparison based sorting and\n  lookup.\n\n- **Performance Focus**: This is systems code. Everything has to be well\n  optimized and cache-coherent without causing code bloat. This codebase avoids\n  exceptions and RTTI for efficiency. Exceptions will be caught by the test\n  driver and the console if they are enabled.\n\n- **C99 Compatibility**: Logging, asserts, and memory management are available\n  in plain C99 via `\u003chx/libhatchet.h\u003e`.\n\n- **64-bit Ready**: Designed for both 32-bit and 64-bit targets.\n\n- **Fast builds**: Blazing fast builds when used with `ccache` and no `.pch`.\n  `ninja` + `ccache` is recommended when using `cmake`. Precompiled headers have\n  surprisingly long load times and break `ccache`'s optimizations. One warning\n  though, this is also accomplished by skipping less commonly used features.\n\n- **AI Friendly**: Things with the same name as the standard generally work the\n  same way as the standard. This means that AI is easily able to apply its\n  existing knowledge of standard C++. It also already knows how to use the test\n  macros when writing tests. Using tabs instead of spaces reduces token use.\n\n- **constexpr ready**: C++11 `constexpr` are used where possible. Asserts,\n  algorithms, `hxlist`, `hxbitset` and `hxrandom` support `consteval` in C++23.\n\n## Memory Management\n\nAn optional memory manager is provided that allows for stack based allocators.\nThis removes overhead from permanent and temporary allocations. In complex\napplications additional stacks would be required for streaming different\nresources. Different allocation strategies can also be added.\n\nFancy tools like heaptrack can be used by disabling the memory manager with\n`-DHX_USE_MEMORY_MANAGER=0`. Leak tracking is also built in.\n\n`hxptr` is provided just in case you want a `std::unique_ptr` replacement.\n\n## Documentation\n\nRunning the command `doxygen` with no arguments will generate\n`docs/html/index.html`. The markdown source for the documentation is in the\nheader files at `include/hx/` and is readable as-is. A modern editor should also\nshow the docs in a mouseover box.\n\n## Not Provided\n\nThis project was started for the author's own personal use, and it tries to be\ncomplete enough for ordinary C++ programmers. It was started before a lot of\nsimilar functionality was added to the standard. However, if you find something\nmissing, odds are your favorite AI already knows how add it, or it was omitted\nbecause the C library was deemed sufficient.\n\nThat said, some functionality of the C++ standard library is not worth\nreimplementing here. If you need these things you are advised to use the\nstandard library shipped with your compiler.\n\n- Iterators Library. This codebase intentionally deemphasizes iterators.\n- Ranges Library. This would be a large and pointless rewrite.\n- Strings Library. These are allocation intensive. See the `{fmt}` project.\n\n## Other Projects\n\n- **[musl libc](https://musl.libc.org/)** - This is the recommended C library\n  for use with libhatchet in a freestanding environment.\n- **[{fmt}](https://fmt.dev)** - Has a micro-optimized version of `std::format`.\n  Also has nice features like console colors and a fast `printf` too.\n\n## Tested Environments\n\nAlmost every reasonable gcc and clang warning flag should be safe to enable.\nclang-tidy is also in use. The tested environment is glibc and musl on Ubuntu\n24.04 LTS. See `ubuntu_packages.sh` for a list of required packages for all the\nscripts. The latest MSVC 2022 should be working with most warnings enabled as\nwell. Although the MSVC static analyzer is not being tested.\n\nThe scripted builds exercise the following toolchains, language modes, and\n`HX_HARDENING_MODE` combinations:\n\n| Script | Toolchain | Language Modes | `HX_HARDENING_MODE` | Notes |\n| --- | --- | --- | --- | --- |\n| `debugbuild.sh` | `clang`/`clang++` | C17, C++23 | 0 | 32-bit debug build with ccache and no exceptions/RTTI. |\n| `testcmake.sh` | `cmake` + default compiler | C17, C++23 | 0 (default) | Uses the real Google Test and runs `hxtest` and clang-tidy. |\n| `testcoverage.sh` | `gcc`, `g++` + `--coverage` | C99, C++23 | 0 | Enables `HX_TEST_ERROR_HANDLING=1` and emits `coverage.html`. |\n| `testmatrix.sh` | `gcc`, `clang` (ASan/UBSan) | C99, C17, C++11, C++23 | 0-3 | Sweeps optimization levels and sets `HX_USE_THREADS=0/1/11`. |\n| `teststrip.sh` | `musl-gcc` (static) | C17, C++11/14/17/20 | 3 | Size-focused static build with allocator/library stripping. |\n| `testwasm.sh` | `emcc` | Emscripten defaults (Clang-based C/C++) | 0 (default) | WebAssembly build with allocator disabled and single-thread mode. |\n\n`testall.sh` runs all of the above and also enforces certain naming conventions.\n\nUse `Terminal-\u003eRun Task...` in VS Code to build Windows using `cmake`. Your\nversion of MSVC should be automatically discovered.\n\n## Project Structure\n\nThe scripts are at the top level for easy access.\n\n```text\n├─ 📁 .vscode           # The vscode configuration files.\n├─ 📁 example           # Simple program showing usage.\n├─ 📁 gdb               # GDB scripts for the container classes.\n├─ 📁 include           # This is the directory to add to your include path.\n│   └─ 📁 hx            # These are all the \u003chx/hx*\u003e header files.\n│       └─ 📁 detail    # These are internal header files.\n├─ 📁 src               # C/C++ files that have to be added to your build.\n└─ 📁 test              # An optional test suite.\n```\n\n## License\n\n© 2017-2026 Adrian Johnston. This project is licensed under the terms of the MIT\nlicense found in the `LICENSE.md` file.\n\n🪓🪓🪓\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwhatchamacallem%2Flibhatchet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwhatchamacallem%2Flibhatchet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwhatchamacallem%2Flibhatchet/lists"}