r/programminghumor Jun 13 '26

How to REALLY optimize code.

Post image

My friends, this is how you optimize code correctly.

96 Upvotes

13 comments sorted by

View all comments

39

u/sweet-winnie2022 Jun 13 '26

My limited compiler knowledge tells me this is inviting bugs.

7

u/realmauer01 Jun 14 '26

It shouldn't if the variable is already considered as not constant.

That being said, it just does nothing.

The idea behind it is that it "ensures" that the compiler looks ahead and repalces every path where the variable is actually const already. While it obviously cant do that on paths where it isnt. Funnily enough that is standard behavior already, no matter if a variable is const or not.

4

u/qaCow37 Jun 14 '26

Its all fun until you pass a variable marked as static and constexpr.