Everyone knows that global variables are a Bad Thing. It's not too clear why they're bad, but it probably has something to do with speed. Think about it. You never know where a Global could be (it could be across the Globe, after all!). But a Local variable -- it's always right there, nearby.

Serge's colleague discovered a way to gain all the benefits of global variables without hampering performance too much ...

bool ReturnBool(void)
{
    static bool bBoolToReturn = false;
    static bool bInitialized = false;

    if (bInitialized == false)
    {
        bBoolToReturn = bGlobalBool;
        bInitialized = true;
    }
    return bBoolToReturn;
}

 

[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!