Static in C++

Hey, its been a really long time. I couldn’t get my adsense account approved. It seems I need more content. If only I spend enough time blogging. Everyone gets busy once in a while. And everyone forgets that they have a blog. Especially ones like mine, where people rarely visit. Anyways, that’s relevant to what I wanted to make note of here. I was working on a minor change in my company’s C++ code base. Its a simple one for anyone who knows C++. But I don’t do much C++. The last time I remember writing real C++ code was during my university days. I mean my bachelors degree. During my masters I worked solely on Java based stuff for my projects and for a coursework, I just opted to do something in ASP .NET, just to get a feel of it. Coming straight back to the point. Static is an overused keyword. Literally it would mean something that doesn’t change. But in C++, this keyword has special meanings, depending on the context it is used. Static can be used for three purposes. One use is to have a variable defined that has a lifetime of the whole program. That is once you declare it static and initialize it, then that variable’s value can be accessed from anywhere in that program. That variable’s allocation is cleared up only when the program closes or quits. And it helps prevent re-initialization. If I were to write something like this: ...

July 18, 2012 · 4 min · 736 words