C/C++ The purpose of static const local variable

c, c++, static

Solution

It doesn't take up stack-space may be a benefit if you have something like:

static const double table[fairly_large_number] = { .... };

Obviously, cost of construction can also be substantial enough that if the function is called a lot, there's good value in only constructing the object once.

Problem

In C and C++, what is the advantage of making a local `const` variable `static`? Assuming the initialization does not use other variables, is there any difference between preserving the value between calls, and setting the same constant value each call? Could a valid C compiler ignore the `static`? In C++, it avoids the construction/destruction between calls, but could there be any other benefit?

Original source

Related problems