Share one AVR handler between vectors with ISR_ALIASOF
Point a second AVR interrupt vector at an existing handler with ISR_ALIASOF from avr-libc 2.2, so both vectors share one function body.
Two interrupt sources sometimes need identical handling, for example pin-change interrupts on two ports that both just set a flag. Copying the body wastes flash, and a shared function called from two handlers adds a call and a return. The avr-libc ISR macro takes an ISR_ALIASOF argument, which makes the second vector an alias of the first. It is documented in the avr/interrupt.h section of avr-libc 2.2.
#include <avr/io.h>
#include <avr/interrupt.h>
volatile uint8_t pin_event;
ISR(PCINT0_vect)
{
pin_event = 1;
}
ISR(PCINT1_vect, ISR_ALIASOF(PCINT0_vect));__vector_3 and __vector_4 resolve to the same addressThe compiler emits one function body and gives it two symbol names, so the vector table entries for PCINT0 and PCINT1 both end up at the same code. Nothing changes in the table itself. On the ATmega328P these are vectors 3 and 4, as the datasheet's interrupt table lists. The second line carries no body, only a semicolon.
The shared handler cannot tell which vector fired, because both enter at the same instruction. If the two sources need different action, read the port pins to find out, or keep separate handlers. The alias also only works for handlers in the same translation unit, as the macro's documentation points out.