compat.safeint
#includeHeader-only checked integer arithmetic for C++ and C
#include <SafeInt.hpp>
mcpp add compat.safeint@3.0.28a
用法
來自本倉庫自己的測試專案 —— CI 真的編譯並執行過,不是為了網站寫的。
// 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 · 專案 tests/examples/safeint
建置
- targets
safeint (lib)- language
c++23- C standard
c11- import std
- no
- include dirs
*
原始檔 (1)
mcpp_generated/safeint_anchor.c
產生的檔案
mcpp_generated/safeint_anchor.c
版本
| 版本 | 平台 | 鏡像 | sha256 |
|---|---|---|---|
3.0.28a 最新 |
LinuxWindowsmacOS | 來源 | 9e652d065a3c… |