compat.safeint
#includeHeader-only checked integer arithmetic for C++ and C
#include <SafeInt.hpp>
mcpp add compat.safeint@3.0.28a
Usage
From this repository's own test project — built and run by CI, not written for the website.
// compat.safeint — assert the C++ class's normal arithmetic, non-throwing cast
// check, and both overflow and divide-by-zero exception paths.
#include <SafeInt.hpp>
#include <cstdint>
#include <cstdio>
#include <limits>
int main() {
bool ok = true;
auto check = [&](bool condition, const char* what) {
if (!condition) {
std::printf("FAIL: %s\n", what);
ok = false;
}
};
SafeInt<std::int32_t> lhs = 40;
SafeInt<std::int32_t> rhs = 2;
check(static_cast<std::int32_t>(lhs + rhs) == 42,
"SafeInt addition");
check(static_cast<std::int32_t>((lhs + rhs) * 2) == 84,
// …
tests/examples/safeint/tests/safeint.cpp · project tests/examples/safeint
Build
- targets
safeint (lib)- language
c++23- C standard
c11- import std
- no
- include dirs
*
Sources (1)
mcpp_generated/safeint_anchor.c
Generated files
mcpp_generated/safeint_anchor.c
Versions
| Version | Platforms | Mirrors | sha256 |
|---|---|---|---|
3.0.28a latest |
LinuxWindowsmacOS | source | 9e652d065a3c… |