LwUTIL is a lightweight utility library that collects small helper macros and functions for value comparisons, bit manipulation, endian-aware serialization and a few common algorithms, commonly hand-written again and again in day-to-day C/C++ development.
- Written in C (C11), compatible with
stdint.hdata types - No dynamic memory allocation
- Get the minimum or maximum of two values, constrain a value to a range, or map it between two ranges
- Get the absolute value of a signed input
- Silence "unused variable" compiler warnings
- Dereference and assign through a pointer, but only when it is not
NULL - Compute the number of elements in a statically allocated array, with
LWUTIL_ASZas a short alias - Store and load
16-bitand32-bitvalues to and from a byte buffer, in little- or big-endian format- Pointer-advancing extended variants are available for sequential (de)serialization
- Set, clear, toggle or check bits against a bit mask
- Convert
8/16/32-bitvalues to their hexadecimal ASCII representation - Encode and decode
32-bitvalues in variable-length integer (varint) format - Check whether a time period has elapsed against a rolling time reference, useful for non-blocking periodic tasks
- Calculate a rolling (sliding-window) linear regression slope over fixed-step sample data, with helpers to query window capacity/count and reset it
- Assert an expression at compile time
- User friendly MIT license
Usage is very simple. Add the lwutil.c file to your build and make sure the compiler can find lwutil.h in the include paths, or use it as a CMake library
Fresh contributions are always welcome. Simple instructions to proceed:
- Fork Github repository
- Follow C style & coding rules and use
clang-formatto format the code - Create a pull request to
developbranch with new features or bug fixes
Alternatively you may:
- Report a bug
- Ask for a feature request