On Thursday, 14 February 2013 at 13:14:47 UTC, Gopan wrote:
Dear Friends,

I have a callback function which will be called back so many times, say at every second for a week.

void TimerCallback(int number)
{
    Statement_1;

    if(number == MY_MAGIC_NUMBER)
    {
        /*
I have been waiting for this so far. Now, I have got want I want. So, I don't want to execute the the above if condition for further callbacks.

        IS THERE ANY TECHNIQUE by which I can say HERE that,
from Statement_1, the control can directly go to Statement_3,
        skipping the evaluation of the above if condition?
        If it is not possible, is it a limitation at the
        micro-processor architecture level?
        */
    }

    Statement_3;
}

Thank you.

You can use static variables inside that function:

void
TimerCallback(int number) {
    statement_1;

    static bool i_found_my_magic_number = false;

    if(!i_found_my_magic_number && number == MY_MAGIC_NUMBER) {
        i_found_my_magic_number = true;
        // Do what you need.
    }

    statement_3;
}

Static variables does not lose its value over different function calls, so you can use it to control what happen inside functions over calls without using global variables.

Hope that helps.

Reply via email to