From d1e6f91f85ba81394297ba72271226ece7047303 Mon Sep 17 00:00:00 2001 From: practicalswift Date: Wed, 16 Aug 2017 21:22:56 +0200 Subject: [PATCH] Prefer compile-time checking over run-time checking --- doc/developer-notes.md | 1 + src/arith_uint256.h | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/developer-notes.md b/doc/developer-notes.md index 461d7e1dc..77260bbdf 100644 --- a/doc/developer-notes.md +++ b/doc/developer-notes.md @@ -37,6 +37,7 @@ code. - **Miscellaneous** - `++i` is preferred over `i++`. + - `static_assert` is preferred over `assert` where possible. Generally; compile-time checking is preferred over run-time checking. Block style example: ```c++ diff --git a/src/arith_uint256.h b/src/arith_uint256.h index 6223e4afe..5fd4fe96c 100644 --- a/src/arith_uint256.h +++ b/src/arith_uint256.h @@ -250,7 +250,7 @@ public: uint64_t GetLow64() const { - assert(WIDTH >= 2); + static_assert(WIDTH >= 2, "Assertion WIDTH >= 2 failed (WIDTH = BITS / 32). BITS is a template parameter."); return pn[0] | (uint64_t)pn[1] << 32; } };