Skip to content

Commit 1e65f0f

Browse files
Use compile-time constants instead of unnamed enumerations (remove "enum hack")
1 parent 1caafa6 commit 1e65f0f

File tree

5 files changed

+14
-20
lines changed

5 files changed

+14
-20
lines changed

src/arith_uint256.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ template<unsigned int BITS>
2525
class base_uint
2626
{
2727
protected:
28-
enum { WIDTH=BITS/32 };
28+
static constexpr int WIDTH = BITS / 32;
2929
uint32_t pn[WIDTH];
3030
public:
3131

src/chain.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ class CBlockIndex
304304
return (int64_t)nTimeMax;
305305
}
306306

307-
enum { nMedianTimeSpan=11 };
307+
static constexpr int nMedianTimeSpan = 11;
308308

309309
int64_t GetMedianTimePast() const
310310
{

src/consensus/consensus.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,9 @@ static const size_t MIN_TRANSACTION_WEIGHT = WITNESS_SCALE_FACTOR * 60; // 60 is
2424
static const size_t MIN_SERIALIZABLE_TRANSACTION_WEIGHT = WITNESS_SCALE_FACTOR * 10; // 10 is the lower bound for the size of a serialized CTransaction
2525

2626
/** Flags for nSequence and nLockTime locks */
27-
enum {
28-
/* Interpret sequence numbers as relative lock-time constraints. */
29-
LOCKTIME_VERIFY_SEQUENCE = (1 << 0),
30-
31-
/* Use GetMedianTimePast() instead of nTime for end point timestamp. */
32-
LOCKTIME_MEDIAN_TIME_PAST = (1 << 1),
33-
};
27+
/** Interpret sequence numbers as relative lock-time constraints. */
28+
static constexpr unsigned int LOCKTIME_VERIFY_SEQUENCE = (1 << 0);
29+
/** Use GetMedianTimePast() instead of nTime for end point timestamp. */
30+
static constexpr unsigned int LOCKTIME_MEDIAN_TIME_PAST = (1 << 1);
3431

3532
#endif // BITCOIN_CONSENSUS_CONSENSUS_H

src/protocol.h

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,13 @@
2727
class CMessageHeader
2828
{
2929
public:
30-
enum {
31-
MESSAGE_START_SIZE = 4,
32-
COMMAND_SIZE = 12,
33-
MESSAGE_SIZE_SIZE = 4,
34-
CHECKSUM_SIZE = 4,
35-
36-
MESSAGE_SIZE_OFFSET = MESSAGE_START_SIZE + COMMAND_SIZE,
37-
CHECKSUM_OFFSET = MESSAGE_SIZE_OFFSET + MESSAGE_SIZE_SIZE,
38-
HEADER_SIZE = MESSAGE_START_SIZE + COMMAND_SIZE + MESSAGE_SIZE_SIZE + CHECKSUM_SIZE
39-
};
30+
static constexpr size_t MESSAGE_START_SIZE = 4;
31+
static constexpr size_t COMMAND_SIZE = 12;
32+
static constexpr size_t MESSAGE_SIZE_SIZE = 4;
33+
static constexpr size_t CHECKSUM_SIZE = 4;
34+
static constexpr size_t MESSAGE_SIZE_OFFSET = MESSAGE_START_SIZE + COMMAND_SIZE;
35+
static constexpr size_t CHECKSUM_OFFSET = MESSAGE_SIZE_OFFSET + MESSAGE_SIZE_SIZE;
36+
static constexpr size_t HEADER_SIZE = MESSAGE_START_SIZE + COMMAND_SIZE + MESSAGE_SIZE_SIZE + CHECKSUM_SIZE;
4037
typedef unsigned char MessageStartChars[MESSAGE_START_SIZE];
4138

4239
CMessageHeader(const MessageStartChars& pchMessageStartIn);

src/uint256.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ template<unsigned int BITS>
1919
class base_blob
2020
{
2121
protected:
22-
enum { WIDTH=BITS/8 };
22+
static constexpr int WIDTH = BITS / 8;
2323
uint8_t data[WIDTH];
2424
public:
2525
base_blob()

0 commit comments

Comments
 (0)