TheCherno / Sparky

Cross-Platform High Performance 2D/3D game engine for people like me who like to write code.
Apache License 2.0
1.09k stars 222 forks source link

STRINGFORMAT_BUFFER_SIZE as constexpr #57

Closed dhustkoder closed 8 years ago

dhustkoder commented 8 years ago

proposal: changing #defines Which contains math operations to ' constexpr ' (compile-time variable).

JeppeSRC commented 8 years ago

I think it's very likely that the compiler will calculate that anyway.

dhustkoder commented 8 years ago

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

TheCherno commented 8 years ago

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.

dhustkoder commented 8 years ago

Alright closing.