Skip to content
MaJerlePublic

About

A small, portable toolkit for C developers: math macros, bit flags, endian serialization, hex ASCII, varints, a period scheduler, and a rolling slope detector

Resources

Stars

83 stars

Watchers

4 watching

Forks

Repository files navigation

C language utility library

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.

Open documentation

Features

  • Written in C (C11), compatible with stdint.h data 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_ASZ as a short alias
  • Store and load 16-bit and 32-bit values 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-bit values to their hexadecimal ASCII representation
  • Encode and decode 32-bit values 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

How to use

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

Contribute

Fresh contributions are always welcome. Simple instructions to proceed:

  1. Fork Github repository
  2. Follow C style & coding rules and use clang-format to format the code
  3. Create a pull request to develop branch with new features or bug fixes

Alternatively you may:

  1. Report a bug
  2. Ask for a feature request

About

A small, portable toolkit for C developers: math macros, bit flags, endian serialization, hex ASCII, varints, a period scheduler, and a rolling slope detector

Resources

Stars

83 stars

Watchers

4 watching

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages