summaryrefslogtreecommitdiff
path: root/gr-blocks/lib/add_const_cc_impl.h
diff options
context:
space:
mode:
authorThomas Habets <habets@google.com>2019-11-20 12:30:19 +0000
committerMartin Braun <martin.braun@ettus.com>2020-01-04 22:35:12 -0800
commit27a466a9c8a03392270fadde9e5bafef5c062e61 (patch)
treeb7b8ce04ef2b95cb663fc06faad4a866062007e6 /gr-blocks/lib/add_const_cc_impl.h
parent8c6657f5edad34f3a1058a676f737536be16ce20 (diff)
Replace many `const` variables with `constexpr`
constexpr is like const but (for variables) guarantees evaluation at compile time (as opposed to runtime). Likely this change will do nothing on its own (though it could, since it gives the compiler more information). But it still has benefits. It allows programmer to know that initialization is not expensive (it was done at compile time), and reduces risk of a refactoring regressing the compiletimeness. Runtime initialization can be nonobvious in larger codebases. E.g.: struct S { static int foo(); }; const int bar = S::foo(); // Called and initialized at *runtime*. int S::foo() { return 10; } With constexpr: struct S { static constexpr int foo(); }; constexpr int bar = S::foo(); // Error: used before definition. constexpr int S::foo() { return 10; } Initializing at runtime is not just startup costs, but also can save memory since it'll end up in a R/O section of a binary and therefore doesn't need to be swapped out, but can be shared (in the mmap() sense of the word).
Diffstat (limited to 'gr-blocks/lib/add_const_cc_impl.h')
0 files changed, 0 insertions, 0 deletions