Closed dhustkoder closed 8 years ago
I think it's very likely that the compiler will calculate that anyway.
yes that's true, but there are some advantages using constexpr like better type safety, and you can look at the math operation's result by landing the cursor above it in VS. It's just a simple proposal, it can help more if constexpr functions are within the project of course. Thanks for replying
In this case we don't have to use constexpr
, since we're just multiplying to literals that are obviously known at compile time. I wrote 10 * 1024
instead of 10240
just for readability, but it will definitely be converted into the latter by any compiler at compile time. We might as well just use const int STRINGFORMAT_BUFFER_SIZE = 1024 * 10;
and it would be exactly the same.
If we were using const functions or something, that would be a different story. But for this example, there's no difference. constexpr
also isn't supported pre-VS2015.
Alright closing.
proposal: changing #defines Which contains math operations to ' constexpr ' (compile-time variable).