This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

goto to a pointer

Hello NG,
I've got the following problem: I want to store the current position in a interrupt routine and leave it. By entering the routine after the next interrupt, I want to jump to this stored position. My first idea was the following:

void irq (void) interrupt 0x14 using irq_level_2
{
static int flag = 0;
static void (*cont_here) ();

if (flag!=0) goto *cont_here;
...
if (something)
{
flag = 1;
cont_here = &here1;
goto end_irq;
}
here1:
...
if (something_else)
{
flag = 1;
cont_here = &here2;
goto end_irq;
}
here2:
...
end_irq:
}

But it doesn't work, 'cause labels and variables aren't the same and goto *bla doesn't work.
Is there a solution besides the using of setjmp and longjump (which got too much, in this case, senseless overhead)?

Thanks for any ideas - Peter

Parents
  • The simplest code is to use a switch statement.

    enum{ State0, State1, State2 };
    
    void irq (void) interrupt 0x14 using irq_level_2
    {
      static unsigned char State;
    
      switch( State )
      {
      State0:
        //do stuff
        State = State1;
        break;
      State1:
        //do stuff
        State = State2;
        break;
      State2:
        //do stuff
        State = State0;
        break;
      }
    }
    

Reply
  • The simplest code is to use a switch statement.

    enum{ State0, State1, State2 };
    
    void irq (void) interrupt 0x14 using irq_level_2
    {
      static unsigned char State;
    
      switch( State )
      {
      State0:
        //do stuff
        State = State1;
        break;
      State1:
        //do stuff
        State = State2;
        break;
      State2:
        //do stuff
        State = State0;
        break;
      }
    }
    

Children
No data