Expand Arduino abstraction in interrupts

I recently noticed that although pin 2 on different arduino boards has arduino interrupt 0 on it, it represent different AVR INT pins. On 328, arduino pin 2 has INT0. On 2560, arduino pin 2 has INT4. These interrupts have different flag bits. When you attach an interrupt routine, you may want to clear the flag of the corresponding interrupt so that your routine doesn't immediately fire on a previously caught interrupt request. It makes sense to add a macro clearInterruptFlag(int number) so that we can reset the interrupt flag if we choose to. Most scenarios I can think off can benefit from resetting the flag prior to attaching ISR. Right now in order to do it, you need to directly reference the flag register's bits. It makes the code not portable and prone to problems when people try to port their code between boards. Why not defining this macro in Winterrupts.c ? Not having this macro will be more problematic when porting code from UNO to leonardo etc.

Sample code:

clearInterruptFlag(0);
attachInterrupt(my_ISR,0,FALLING);
///...

@liudr
In Cosa there is an abstract Interrupt::Handler class that is inherited by classes with interrupt sources. Strong data typing is used to handle pin parameters. The Board classes define the set of pins available.

The ISRs are trampoline functions to the virtual member function on_interrupt() for the Handler. This has an overhead as the call is indirect and the compiler must push all registers. This is also the case for the Arduino interrupt handler.

Please see the on-line documentation for more details.

Cheers!

We're not talking about the same thing here. What I recommended is for the Arduino core to extend its functions, not another group of libraries and OOP stuff. As you said, all registers are pushed in what you referenced as cosa. If we just change one control register bit, we don't need that kind of complexity.