views:

63

answers:

1

In what ways can a flag be used within the program design?

How can you use multiple flags?

+2  A: 

A flag is usually a boolean value that signals logic in your program to do something.

// set the debug flag on
bool debugFlag = true;

// set the verbose flag to false
bool verbose = false; 

if (debugFlag)
{
    log.currentLine(); // do somthing when in debug mode.
}

if (verbose)
{
     // spew more output than nomral.
    cout<<"verbose flag is on!";
    if (debugFlag)
    {
        log.currentVerboseLine(); // if we are in verbose more send even more data to the log
    }
}

But remember, a semaphore is not a flag!!!!

alt text

Byron Whitlock