skullchap/chadstr
FreeChad Strings - The Chad way to handle strings in C.
About skullchap/chadstr
Chad Strings (chadstr) is a single-header C library that provides a minimalist and unconventional approach to string handling through a powerful str() macro. It enables concatenation of multiple strings, integers, shell commands, and substrings in a single expression. The library integrates with OS command-line tools via a cmd struct, allowing shell-like operations directly in C. It also offers a range() function for substring extraction, supports zero-indexed and one-indexed ranges via HUMAN_RANGE, and optional automatic memory deallocation using GCC/Clang's __attribute__((cleanup())). Designed for quick prototyping and short-lived programs, it aims to reduce boilerplate by leveraging the OS to manage memory and perform string operations.
Key Features
Pros & Cons
- Simplifies complex string operations into a single macro call
- Leverages existing OS tools (echo, cat, cut) for powerful text processing
- Minimal boilerplate – single header, no build configuration needed
- Optional automatic memory management reduces manual free() calls
- Supports both zero-based and one-based indexing for substring ranges
- Automatic memory deallocation relies on GCC/Clang extension (`cleanup`), not portable to all compilers
- Memory is not automatically freed unless using the `autofree` type or `__attribute__((cleanup()))` – leaks possible in long-running applications
- Heavy reliance on shell commands may introduce security risks if input is untrusted
- Non-standard approach may be unfamiliar and harder to debug for many C developers
- Designed for short-lived programs (author states OS cleans memory), unsuitable for production where explicit resource management is required