diff --git a/src/Makefile.am b/src/Makefile.am index a57fcb07110b00..d739dcc28fad4d 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -102,6 +102,7 @@ endif BITCOIN_CORE_H = \ addrdb.h \ addrman.h \ + assumptions.h \ attributes.h \ banman.h \ base58.h \ diff --git a/src/assumptions.h b/src/assumptions.h new file mode 100644 index 00000000000000..10ea9ac1490ea3 --- /dev/null +++ b/src/assumptions.h @@ -0,0 +1,29 @@ +// Copyright (c) 2009-2010 Satoshi Nakamoto +// Copyright (c) 2009-2019 The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +// Compile-time verification of assumptions we make. + +#ifndef BITCOIN_ASSUMPTIONS_H +#define BITCOIN_ASSUMPTIONS_H + +#include +#include + +// Assumption: We assume the floating-point types to fulfill the requirements of IEC 559 (IEEE 754) standard. +// Example(s): Floating-point division by zero in ConnectBlock, CreateTransaction and EstimateMedianVal. +static_assert(std::numeric_limits::is_iec559, "IEEE 754 float assumed"); +static_assert(std::numeric_limits::is_iec559, "IEEE 754 double assumed"); + +// Assumption: We assume floating-point widths. +// Example(s): Type punning in serialization code (ser_{float,double}_to_uint{32,64}). +static_assert(sizeof(float) * CHAR_BIT == 32 && CHAR_BIT == 8, "32-bit float assumed"); +static_assert(sizeof(double) * CHAR_BIT == 64 && CHAR_BIT == 8, "64-bit double assumed"); + +// Assumption: We assume integer widths. +// Example(s): GetSizeOfCompactSize and WriteCompactSize in the serialization code. +static_assert(sizeof(short) * CHAR_BIT == 16 && CHAR_BIT == 8, "16-bit short assumed"); +static_assert(sizeof(int) * CHAR_BIT == 32 && CHAR_BIT == 8, "32-bit int assumed"); + +#endif // BITCOIN_ASSUMPTIONS_H diff --git a/src/util/system.h b/src/util/system.h index 17723d427dadee..c8aef449a07a28 100644 --- a/src/util/system.h +++ b/src/util/system.h @@ -14,6 +14,7 @@ #include #endif +#include #include #include #include