Use compile-time constants instead of unnamed enumerations (remove "enum hack").
Use compile-time constants instead of unnamed enumerations (remove "enum hack") #10749
pull practicalswift wants to merge 1 commits into bitcoin:master from practicalswift:enum-hack changing 5 files +14 −20-
practicalswift commented at 2:51 PM on July 5, 2017: contributor
- fanquake added the label Refactoring on Jul 5, 2017
-
jonasschnelli commented at 4:13 PM on July 5, 2017: contributor
utACK 0f3d58be40672151468700fb5a05898468814880
-
jgarzik commented at 5:43 PM on July 5, 2017: contributor
This enum technique is a well-defined way to generate typed constants.
Is it causing problems somewhere?
-
TheBlueMatt commented at 6:22 PM on July 5, 2017: member
utACK 0f3d58be40672151468700fb5a05898468814880
- gmaxwell approved
-
gmaxwell commented at 12:53 AM on July 6, 2017: contributor
ACK.
-
benma commented at 11:44 AM on July 25, 2017: none
First time I read about
constexpr, and I also googled for enum vs constexpr. For what it's worth, I've seen quite a few threads that lean towards enums even with constexpr being available, like https://stackoverflow.com/a/37259949.constexpris easier to read, and it doesn't seem to have a downside at least in this PR. -
practicalswift commented at 11:50 AM on July 25, 2017: contributor
@benma I take that as an utACK? :-)
-
Use compile-time constants instead of unnamed enumerations (remove "enum hack") 1e65f0f339
-
in src/consensus/consensus.h:33 in 0f3d58be40 outdated
30 | - /* Interpret sequence numbers as relative lock-time constraints. */ 31 | - LOCKTIME_VERIFY_SEQUENCE = (1 << 0), 32 | - 33 | - /* Use GetMedianTimePast() instead of nTime for end point timestamp. */ 34 | - LOCKTIME_MEDIAN_TIME_PAST = (1 << 1), 35 | -};
benma commented at 4:11 PM on July 25, 2017:Isn't an enum appropriate when it's indeed an enumeration?
Aso, please rebase, as there are other consts that could be constexprs in consensus.h now:
static const size_t MIN_TRANSACTION_WEIGHT = WITNESS_SCALE_FACTOR * 60; // 60 is the lower bound for the size of a valid serialized CTransaction static const size_t MIN_SERIALIZABLE_TRANSACTION_WEIGHT = WITNESS_SCALE_FACTOR * 10; // 10 is the lower bound for the size of a serialized CTransactionStill a bit confused about the whole thing, seems like simple
constwould also suffice. Is the advantage ofconstexprjust that it gives a compile time error in case the expression can't be evaluated at compile time?
practicalswift commented at 10:30 PM on July 25, 2017:- Sure, that case could be made. I can do it as a scoped named enum (
enum class). Any suggestion on a proper name for that enumeration? - The goal of this PR is to get rid of enum hacks. Changing existing
const:s toconstexpr:s is not within that scope :-) - When introducing new compile-time constants I prefer
constexprwhich is explicit about the intention of the code (getting a compile-time constant). Do you see any compelling reasons to avoid usingconstexpr(which impliesconst) for compile-time constants?
benma commented at 2:52 PM on July 26, 2017:Thanks. I just thew in some thoughts in case you can pick something from it. I have no preference either way.
practicalswift force-pushed on Jul 25, 2017practicalswift commented at 10:15 PM on July 25, 2017: contributorRebased!
benma commented at 2:51 PM on July 26, 2017: noneutACK 1e65f0f3396d5d7eaa8e8dd3668dfa180b541c18
jnewbery commented at 4:33 PM on August 17, 2017: memberACK 1e65f0f3396d5d7eaa8e8dd3668dfa180b541c18
MarcoFalke commented at 5:33 PM on November 11, 2017: member-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA512 utACK 1e65f0f3396d5d7eaa8e8dd3668dfa180b541c18 -----BEGIN PGP SIGNATURE----- iQIcBAEBCgAGBQJaBzQQAAoJENLqSFDnUosllrgP/0Jq2acX/JFfphTWDMcGzChi NtMamQFeV1gvGLvUYW7UogT6R1BGCCCJ92OeVZFBQWsLo5ZkrucxQcUYKDnV5gKi 7LCl/8rz6LWmPvJszFPUjvE7/X5Nd6r1crCZJ9oPaO/w4tK8k5UeeI+ODn6+XUFN WaoqP/sxnfeDm90fDybU7aix0yCaDsLZ/rHl6zVFSLQerb4McKG7ji/MjW4Bi/ii wCAYHc9Gzfxa3y3AMaiA+zh/GMSLDBOvLaClWt3UlXI9pfVA9giP+PPgtKAHkz82 2lX+byUyGVK3n5oSBeJD8A4mmcOMvF0DT+6XlvlETX2ApnzZlkzX7tqtDa0w3UtJ Ni1iCzZl11tgqXRTpQYaxTL5YdoDbeudhvz5gmZ+N2wNLIVcmbJSztt62eQI00GW G5LPnWrDtaDOKn7Rv6kVJkgAcel9nIrIibvosQi0anrwVGZ3Fg7GXKY3kEhgwIuO 2YmjXJ5xEhwUDktopn7/Mt/fSeMWeg0Gg7oqGiJ6WCY0nYC9gHPJBd8k9nH/pOCP V61mWhpDRjp+bQZvS6IL0GkQEJ/IPxPgTE4xNrsYMpVgBBPiWhjCy6VnAPbxZHd9 xJVpjJC+QKwR+zfVpoF2VzWKFlf28cfNSNh9z+8q6Juvv6maYUxlPxQ4zgMms8LA 1zrcJiqm/1ySme7GeWhb =a+3Y -----END PGP SIGNATURE-----MarcoFalke merged this on Nov 11, 2017MarcoFalke closed this on Nov 11, 2017MarcoFalke referenced this in commit 2adbddb038 on Nov 11, 2017PastaPastaPasta referenced this in commit 23074882e7 on Jan 17, 2020PastaPastaPasta referenced this in commit f275b3fc70 on Jan 22, 2020PastaPastaPasta referenced this in commit aeaf3c5ef9 on Jan 22, 2020PastaPastaPasta referenced this in commit 3ab405a96b on Jan 29, 2020ckti referenced this in commit 7c42b740fd on Mar 28, 2021practicalswift deleted the branch on Apr 10, 2021gades referenced this in commit 1a88238cf4 on Jun 26, 2021furszy referenced this in commit 60d36292bc on Jul 26, 2021gades referenced this in commit 03df621768 on Feb 5, 2022DrahtBot locked this on Aug 16, 2022 - Sure, that case could be made. I can do it as a scoped named enum (
This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-16 15:15 UTC
More mirrored repositories can be found on mirror.b10c.me