Hey guys, I was watching a video on const constexpr consteval & constinit, and I was at the section justifying constexpr and in it one of the arguments seemed to go like this (paraphrasing massively):
having
3.14fin our code is bad because we have hardcoded the value of pi... We can pull the value of pi into a global constant, but the downside is now that everytime we callarea(area_variable) we will need to access a memory address, making the function ever so slighly more expansive
It goes on about how this can be fixed by macros butconstexprserver this purpose better... Anyway, from looking at this in compiler explorer
const double pi = 3.15f;
double area(const double radius) {
return 3.14f * (radius * radius);
}
double area_variable(const double radius) {
return pi * (radius * radius);
}
Both of these seem identical with -O0 flag, is there a way to make them be different, or was this just a case of "true in general but not for the demonstrative example"?