Using goto during the interrupt

Is it possible to use labels in the interrupt function.
I'm trying to make something like this

volatile int count = 0;

void setup()
{
  attachInterrupt(0, blink, CHANGE);
  Serial.begin(9600);
}

void loop()
{
  label:
  Serial.println(count);

}

void blink()
{ 
  count++;
  goto label;
}

But it doesn't recognize label in this function.
With an interrupt i need to go back to the beginning of the main cycle. Maybe someone has already managed this problem other way? )

Your label is not in scope in your ISR. Interrupts are designed to return to the point the program was at when they were called. It's likely you would corrupt the stack with what you were trying to do.

No you can't do that. Why do you want to?

dxw00d:
Your label is not in scope in your ISR. Interrupts are designed to return to the point the program was at when they were called. It's likely you would corrupt the stack with what you were trying to do.

Its not likely, its a certainty that you'll corrupt the runtime stack!! The only way out of an ISR is by returning.

In general use of goto is a mistake. Sometimes, on rare occasions, longjmp() might be justified, but using goto is always avoidable and should be avoided.

You need to set a boolean flag in the ISR and poll it (ie test it) at suitable points in your "main cycle" code.

Trying to jump out of an ISR is like trying to jump out of an aircraft, mid-flight.

No matter how important your reasons might seem to you, someone will try to talk you out of it ... with good reason.

Ok, i agree, that Goto is bad thing and it's impossible to use it with an interrupts.
I'm trying to do some kind of garland, several LEDs blinking in different order.I want to use a button to change these modes. But some of my modes has a duration time more then 2 seconds. So that Arduino executes that mode till the end, then finds out that, the mode number is already changed and executes that one. But the aim is to change the mode simultaneously with the button pressing, not waiting till the end.

Has someone solved such problem? :slight_smile:

Has someone solved such problem?

Yes.
Look at the blink without delay example, without delay.

But some of my modes has a duration time more then 2 seconds.

Then, those modes need to be restructured, to notice "Hey, I'm supposed to quit doing this...".

Goto is bad thing and it's impossible to use it with an interrupts

1)Yes it is, but it is part of the language and has its place (this isn't it)
2) No-one said it was impossible (it isn't), just that what you were trying do was not possible.

Roman27:
I'm trying to do some kind of garland, several LEDs blinking in different order.I want to use a button to change these modes.

That wasn't obvious from your first post, nor your sample code. More information initially can save a lot of time.