nemequ/portable-snippets
FreeCollection of miscellaneous portable C snippets.
About nemequ/portable-snippets
Portable Snippets is a collection of public domain (CC0) code snippets written in C for performing common tasks that are typically OS, architecture, and/or compiler-dependent. The primary goal is to move those annoying preprocessor conditionals from user code into the snippets. It includes modules for using compiler built-ins/intrinsics (builtin), endianness detection and swapping (endian), atomic synchronization operations (atomic), overflow-safe integer functions (safe-math), exact-width integer types (exact-int), cross-platform clock, CPU time, and monotonic time (clock), fast unaligned loads/stores (unaligned), one-time initialization (once), random number generation (random), debug traps and assertions (debug-trap), and assertion checking (check). The project is continuously tested on multiple compilers (GCC, Clang, MSVC, PGI, Emscripten) and encourages community contributions.
Key Features
Pros & Cons
- Public domain (CC0) license for unrestricted use
- Continuously tested on GCC, Clang, MSVC, PGI, and Emscripten
- Modules are independent, can be used in isolation
- Active repository with community contributions
- Covers many common portability issues
- Requires manual inclusion of snippets (not a library)
- Some modules are experimental (e.g., unaligned, once, random)
- Limited to C (no C++ or other languages directly)