CPB Mailing List
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: static functions
>>int anotherFunction()
>>{
>> static int beenHere; // declared in same memory segment as "foofoo"
>> // but is only available to this function. It
>> // is not on the stack, and retains its value
>> // between invocations of this function. Also, it
>> // is not initialized until the first call to
>> // this function.
>>}
>>
>
>
>Not true. Because it is static, by definition it will be initialized to 0
>(zero) before main() is called.
>
>Cheers,
>Scott.
Actually, the first description is correct. Static locals only get
initialized/constructed when the thread of execution passes through them
for the first time. They are destroyed/destructed when the program exits.
(see The C++ Programming Language, 3rd ed., Bjarne Stroustrup, section
10.4.8 - Local Static Store, pg 251.)
Static globals are, however, initialized as Scott described...
On the issue of static functions within classes, the only thing I can add
is that static member functions don't have the 'this' pointer implicitly
passed into the function when it is called, as is normally the case when a
non-static member function is called.
HTH,
Ken
W Komornicki's Home Page |
Main Index |
Thread Index