Re: using local static variable inside a function
On Sep 30, 7:51 pm, Noah Roberts <d...@reply.com> wrote:
In article <f7326314-4217-44d2-8d1e-25b2bc92b7d1@
31g2000vbf.googlegroups.com>, subramanian10...@yahoo.com says...
Is it advisable to use a local static variable inside a
function ? I want to know whether there are any drawbacks of
using local static variable inside a function.
They aren't thread safe.
That depends on how they are used.
But I think you mean that their initialization isn't inherently
thread safe. Except that as Pete Becker points out, that's not
really the case---the standard, of course, doesn't say anything,
but from a QoI point of view, if the compiler supports threading
otherwise, it should also arrange for the initialization to be
thread safe. (Of course, from this point of view, there are a
lot of compilers whose quality isn't that good.)
They are often used when they're not needed and can make
otherwise simple problems difficult.
Doesn't that apply to just about everything in C++? Templates
are an obvious example (because they're the current mode), but
I've seen cases of overuse of just about every feature of C++.
On the other hand, most features are there for a reason, and not
using local statics can also make otherwise simple problems
difficult. It all depends on the problem.
--
James Kanze